"type"是JavaScript中的关键字吗?

cra*_*man 21 javascript ecmascript-6

我刚刚在一段ES6代码中遇到过使用"type"的人.

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,
  };
Run Code Online (Sandbox Code Playgroud)

找不到任何能够揭示它的东西.它是关键字吗?它到底是做什么的?

lin*_*3rd 17

正如PitaJ所提到的,type这里的符号不是ES6的一部分,而是Flow静态类型检查器的一部分.

这是type符号的文档.


arc*_*rty 5

据我所知,ES6 规范并未将其列为保留关键字。

以下标记是 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