“类型”是 JavaScript 中的关键字吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33446498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is "type" a keyword in JavaScript?
提问by craftsman
I just came across somebody using "type" in a piece of ES6 code.
我刚刚遇到有人在一段 ES6 代码中使用“类型” 。
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?
找不到任何可以阐明它的东西。是关键词吗?它究竟有什么作用?
采纳答案by linusthe3rd
As mentioned by PitaJ, the type
symbol here is not part of ES6 or any earlier version of JavaScript, but rather part of the Flow static type checker.
正如PitaJ所提到的,type
这里的符号不是 ES6 或任何早期版本的 JavaScript 的一部分,而是Flow 静态类型检查器的一部分。
回答by arcyqwerty
As far as I know, the ES6 specdoes not list it as a reserved keyword.
据我所知,ES6 规范并未将其列为保留关键字。
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
以下标记是 ECMAScript 关键字,不得用作 ECMAScript 程序中的标识符。
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
回答by Nver Abgaryan
You can disable it
你可以禁用它
export interface Body {
a: string
b: string
c: string
// tslint:disable-next-line:no-reserved-keywords
type: string
f: string
e: string
}