Skip to content

Latest commit

 

History

History
130 lines (108 loc) · 4.85 KB

README.md

File metadata and controls

130 lines (108 loc) · 4.85 KB

ES Type Hints

Syntax

TODO TypeHint

TypeHint[Yield] :
  [~Yield] IdentifierReference[~Yield]
  number
  string
  boolean
  void

12.2.6 Object Initializer

PropertyDefinition[Yield] :
  IdentifierReference[?Yield] TypeHint[?Yield]opt
  CoverInitializedName[?Yield]
  PropertyName[?Yield] : AssignmentExpression[In, ?Yield]
  MethodDefinition[?Yield]

PropertyName[Yield,GeneratorParameter] :
  LiteralPropertyName
  [+GeneratorParameter] ComputedPropertyName TypeHint[?Yield]opt
  [~GeneratorParameter] ComputedPropertyName[?Yield] TypeHint[?Yield]opt

LiteralPropertyName :
  IdentifierName TypeHintopt
  StringLiteral
  NumericLiteral

CoverInitializedName[Yield] :
  IdentifierReference[?Yield] TypeHint[?Yield]opt Initializer[In, ?Yield]


12.14.5 Destructuring Assignment

AssignmentProperty[Yield] :
  IdentifierReference[?Yield] TypeHint[?Yield]opt Initializer[In,?Yield]opt
  PropertyName TypeHint[?Yield] : AssignmentElement[?Yield]

13.3.1 Let and Const Declarations

LexicalBinding[In, Yield] :
  BindingIdentifier[?Yield] TypeHint[?Yield]opt Initializer[?In, ?Yield]opt
  BindingPattern[?Yield] Initializer[?In, ?Yield]

13.3.2 Variable Statement

VariableDeclaration[In, Yield] :
  BindingIdentifier[?Yield] TypeHint[?Yield]opt Initializer[?In, ?Yield]opt
  BindingPattern[?Yield] Initializer[?In, ?Yield]

13.3.3 Destructuring Binding Patterns

SingleNameBinding [Yield, GeneratorParameter] :
  [+GeneratorParameter] BindingIdentifier[Yield] TypeHint[?Yield]opt Initializer[In]opt
  [~GeneratorParameter] BindingIdentifier[?Yield] TypeHint[?Yield]opt Initializer[In, ?Yield]opt

13.7 Iteration Statements

ForBinding[Yield] :
  BindingIdentifier[?Yield] TypeHint[?Yield]opt
  BindingPattern[?Yield]

14.1 Function Definitions

FunctionDeclaration[Yield, Default] :
  function BindingIdentifier[?Yield] ( FormalParameters ) TypeHint[?Yield]opt { FunctionBody }
  [+Default] function ( FormalParameters ) TypeHint[?Yield]opt { FunctionBody }
FunctionExpression :
  function BindingIdentifieropt ( FormalParameters ) TypeHint[?Yield]opt { FunctionBody }

FormalParameter[Yield,GeneratorParameter] :
  BindingElement[?Yield, ?GeneratorParameter] TypeHint[?Yield]opt

14.2 Arrow Function Definitions

ArrowParameters[Yield] :
  BindingIdentifier[?Yield] TypeHint[?Yield]opt
  CoverParenthesizedExpressionAndArrowParameterList[?Yield] TypeHint[?Yield]opt
  

TODO: semantics of what TypeHint is attached to.

14.3 Method Definitions

MethodDefinition[Yield] :
  PropertyName[?Yield] ( StrictFormalParameters ) TypeHint[?Yield]opt { FunctionBody }
  GeneratorMethod[?Yield]
  get PropertyName[?Yield] ( ) TypeHint[?Yield]opt { FunctionBody }
  set PropertyName[?Yield] ( PropertySetParameterList ) TypeHint[?Yield]opt { FunctionBody }

TODO: static semantics of set's typehint, it should be a syntax error if it's not empty, or "void"

14.4 Generator Function Definitions

GeneratorMethod[Yield] :
  * PropertyName[?Yield] ( StrictFormalParameters[Yield,GeneratorParameter] ) TypeHint[?Yield]opt { GeneratorBody }
GeneratorDeclaration[Yield, Default] :
  function * BindingIdentifier[?Yield] ( FormalParameters[Yield,GeneratorParameter] ) TypeHint[?Yield]opt { GeneratorBody }
  [+Default] function * ( FormalParameters[Yield,GeneratorParameter] ) TypeHint[?Yield]opt { GeneratorBody }
GeneratorExpression :
  function * BindingIdentifier[Yield]opt ( FormalParameters[Yield,GeneratorParameter] ) TypeHint[?Yield]opt { GeneratorBody }

Prior Art:

Type Hinting:

Type Checking/Annotations: