我希望TypeScript在映射到这样的联合时强制执行穷举:
type Union =
{ type: 'A', a: string } |
{ type: 'B', b: number }
Run Code Online (Sandbox Code Playgroud)
Union事件处理程序:
const handle = (u: Union): string =>
theMap[u.type](u);
Run Code Online (Sandbox Code Playgroud)
如果在这里我们能以某种方式从TypeScript获得详尽的检查,那就太好了:
const theMap: { [a: string]: (u: Union) => string } = {
A: ({a}: { type: 'A', a: string }) => 'this is a: ' + a,
B: ({b}: { type: 'B', b: number }) => 'this is b: ' + b
};
Run Code Online (Sandbox Code Playgroud) 尝试用声音类型实现功能性的拨动,但我做错了:
function pluck<Object extends {}, Key = keyof Object>(key: Key): (o: Object) => Object[Key] {
return object => object[key];
}
Run Code Online (Sandbox Code Playgroud)
TS错误:
类型“Key”不能用于索引类型“Object”
在某些点击或单击时,我需要将焦点放在视口之外但正在动画中的输入上。但是,由于浏览器如何立即将聚焦元素滚动到视图中,我的转换被搞砸了。
所以简单的问题是,如何防止焦点输入/文本区域元素的自动滚动?
以下是不良行为的示例:
http://jsbin.com/nejiwoy/edit?html,输出
<div
style="
position: relative;
top: 100px;
left: 100px;
width: 200px;
height:100px;
background: gray;
overflow: hidden;
">
<div
style="
position: absolute;
top: 0;
left: 0;
right: 0;
height: 200px;
background: green;
">
<input
style="
position: absolute;
top: 100px;
height: 100px;
width: 100%;
background: yellow;
border: none;
">
</div>
</div>
<button onclick="document.body.querySelector('input').focus()">focus</button>Run Code Online (Sandbox Code Playgroud)
I want to pass the IoT custom endpoint as an env var to a lambda declared in CDK.
I'm talking about the IoT custom endpoint that lives here:

How do I get it in context of CDK?
当我尝试通过serverless-domain-manager设置域时sls create_domain,它失败了:
BadRequestException:您提供的域名已与现有CloudFront分配相关联.从现有CloudFront分配中删除域名或使用其他域名.如果您拥有此域名且未在现有CloudFront分配中使用该域名,请与支持部门联系.没有创建api.example.com.
请注意,我的帐户在CloudFront中没有任何内容.这是我打开它时看到的:
在Associated Resources下我可以看到cloudfront的条目: arn:aws:cloudfront:: ...
amazon-web-services amazon-cloudfront amazon-route53 serverless-framework
阅读投影表达式文档并没有给我足够的技术细节来了解我们通过使用它们究竟能节省什么。
对于一些上下文,我正在尝试为多语言项目确定数据结构:
选项A:
{
id: 'yes',
en: 'Yes',
es: 'Si'
},
{
id: 'no',
en: 'No',
es: 'No'
}
Run Code Online (Sandbox Code Playgroud)
选项 B:
{
id: 'en',
yes: 'Yes',
no: 'No'
},
{
id: 'es',
yes: 'Si',
no: 'No'
}
Run Code Online (Sandbox Code Playgroud)
虽然选择选项 A 似乎很明显,但我有一个相互矛盾的用例:当客户端应用程序启动时,它需要获取 UI 的整批字符串。因此,对于选项 A,这可能意味着对 300 个项目进行批量查询。不理想。
我正在 DynamoDb 中对每周报告商店进行建模。
我认为识别报告记录的最佳方法是通过自 1970 年以来各自的周数。很像纪元毫秒。
所以:
考虑到我可能不知道的所有可能的边缘情况,例如夏令时等,我在尝试解决此问题时感到非常不舒服。
澄清:
ApiGateway 1 有一个别名,但它的接口不符合 V2:
这是domainName:
const domainName = new apigw2.DomainName(config.scope, config.id + 'DomainName', {
domainName: config.domainName,
certificate: config.certificate,
});
Run Code Online (Sandbox Code Playgroud) 对于http://127.0.0.1:9000/我得到的'/'()路线
不能获取 /
而对于我得到的/ v1路线
未找到
在此服务器上找不到请求的URL/v1.
这是我的Gruntfile.js:
// Generated on 2013-10-08 using generator-webapp 0.4.3
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
/*============================================
= Expose Prxy Function =
============================================*/
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
/*----- End of Expose Prxy Function ------*/
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load …Run Code Online (Sandbox Code Playgroud) typescript ×3
aws-cdk ×2
javascript ×2
types ×2
aws-lambda ×1
css ×1
datetime ×1
elm ×1
gruntjs ×1
html ×1
node.js ×1
nosql ×1
timezone ×1
yeoman ×1