在Atom中,在此特定行上会出现一个灯泡图标.左键单击和右键单击似乎会发出与单击任何其他行的相同部分时相同的行为.
它是什么?它为什么存在,我能做些什么呢?它看起来非常像我在Visual Studio中看到的图标,它通常会显示一些有用的提示来帮助我处理我的代码.
有没有办法对一个对象的"instanceof"式查询对照语言中内置的联合类型?
我有一个带有union类型的类型别名,如下所示:
type MyType = Foo | Bar | Thing;
Run Code Online (Sandbox Code Playgroud)
每一个Foo,Bar并Thing继承自Base
class Base { /* ... */ }
class Foo extends Base { /* ... */ }
class Bar extends Base { /* ... */ }
class Thing extends Base { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
一些方法返回一个Base.
function getBase(): Base { /* ... */ return base; }
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想创建另一个可以返回MyType后调用的方法getBase()
function getMyType(): MyType {
var item = getBase();
if (item instanceof …Run Code Online (Sandbox Code Playgroud) 如何contextTypes在TypeScript中定义?
我有一个组件(注意:我不确定此问题中详述的必要类型的路由器,但这应该与此无关)
export class Repos extends React.Component<ReposProps, {}> {
context: {
router: History
}
static contextTypes = {
router: React.PropTypes.object
};
Run Code Online (Sandbox Code Playgroud)
它有一个功能
public handleSubmit(event: React.FormEvent) {
Run Code Online (Sandbox Code Playgroud)
在该函数的末尾,它调用上下文
this.context.router.push(path);
}
Run Code Online (Sandbox Code Playgroud)
该组件有一个表单
public render() {
return (
{/* ... */}
<form onSubmit={this.handleSubmit}>
);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在this.context.router.push(path);我收到错误"未捕获的TypeError:无法读取未定义的属性'路由器'的错误"编译同样的代码时,我在路由器中使用Repos的文件中收到了TypeScript错误:
ERROR in ./index.tsx
(14,34): error TS2322: Type 'typeof Repos' is not assignable to type 'string | ComponentClass<any> | StatelessComponent<
any>'.
Type 'typeof Repos' is not assignable to type …Run Code Online (Sandbox Code Playgroud) 我正在编写的用于编码UI测试的应用程序有一个窗口,其中窗口标题的一部分基于为临时文件生成的随机文件名,因此测试只能知道窗口标题的静态部分.
偶尔,当没有其他窗口打开时,测试运行正常.但是,当其他窗口打开时,这有点问题.如果其他窗口具有类似的控件,则测试选择哪个窗口是不可预测的.