Is "type" a keyword in JavaScript?

时间:2015-10-30 23:53:24

标签: javascript ecmascript-6

I just came across somebody using "type" in a piece of ES6 code. export type Action = { type: 'todo/complete', id: string, } | { type: 'todo/create', text: string, } | { type: 'todo/destroy', id: string, } | { type: 'todo/destroy-completed', } | { type: 'todo/toggle-complete-all', } | { type: 'todo/undo-complete', id: string, } | { type: 'todo/update-text', id: string, text: string, }; Couldn't find anything that sheds light on it. Is it a keyword? What does it exactly do?

3 个答案:

答案 0 :(得分:14)

正如PitaJ所述,此处的type符号不是ES6或任何早期版本的JavaScript的一部分,而是Flow static type checker的一部分。

Here are the docs for the type symbol

答案 1 :(得分:2)

As far as I know, the ES6 spec does not list it as a reserved keyword. The following tokens are ECMAScript keywords and may not be used as Identifiers in ECMAScript programs. break do in typeof case else instanceof var catch export new void class extends return while const finally super with continue for switch yield debugger function this default if throw delete import try

答案 2 :(得分:1)

您可以禁用它

export interface Body {
   a: string
   b: string
   c: string
   // tslint:disable-next-line:no-reserved-keywords
   type: string
   f: string
   e: string
}