我刚刚注意到,当试图在TypeScript中创建一个接口时,“type”是关键字或保留字。当创建以下接口,例如,“类型”显示为蓝色在Visual Studio 2013年打字稿1.4:TypeScript中的“类型”保留字是什么?
interface IExampleInterface {
type: string;
}
比方说,你再尝试实现接口的类,像这样:
class ExampleClass implements IExampleInterface {
public type: string;
constructor() {
this.type = "Example";
}
}
在类的第一行中,当您键入(对不起)单词“type”以便实现接口所需的属性时,IntelliSense以“type”出现,与其他关键字具有相同图标,例如“ typeof“或”new“。
我看了一下,可以找到这个GitHub issue,它在TypeScript中将“type”列为“严格模式保留字”,但我还没有发现任何有关其实际用途的更多信息。
我怀疑我有一个大脑放屁,这是显而易见的事我应该已经知道,但什么是打字稿“类型”保留字呢?
'键入别名'为您的类型提供语义名称:http://basarat.gitbooks.io/typescript/content/docs/types/type-system.html – basarat