Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "type" a keyword in JavaScript?

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?

like image 749
craftsman Avatar asked Oct 30 '15 23:10

craftsman


3 Answers

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.

Here are the docs for the type symbol.

like image 83
linusthe3rd Avatar answered Nov 11 '22 17:11

linusthe3rd


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

like image 6
arcyqwerty Avatar answered Nov 11 '22 16:11

arcyqwerty


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
}
like image 2
Nver Abgaryan Avatar answered Nov 11 '22 17:11

Nver Abgaryan