You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -27,10 +27,12 @@ TypeScript is a trademark of Microsoft Corporation.
27
27
*[1.10 Modules](#1.10)
28
28
*[2 Basic Concepts](#2)
29
29
*[2.1 Grammar Conventions](#2.1)
30
-
*[2.2 Reserved Words](#2.2)
30
+
*[2.2 Names](#2.2)
31
+
*[2.2.1 Reserved Words](#2.2.1)
32
+
*[2.2.2 Property Names](#2.2.2)
33
+
*[2.2.3 Computed Property Names](#2.2.3)
31
34
*[2.3 Declarations](#2.3)
32
35
*[2.4 Scopes](#2.4)
33
-
*[2.5 Computed Names and Symbols](#2.5)
34
36
*[3 Types](#3)
35
37
*[3.1 The Any Type](#3.1)
36
38
*[3.2 Primitive Types](#3.2)
@@ -178,6 +180,7 @@ TypeScript is a trademark of Microsoft Corporation.
178
180
*[8.4.1 Member Variable Declarations](#8.4.1)
179
181
*[8.4.2 Member Function Declarations](#8.4.2)
180
182
*[8.4.3 Member Accessor Declarations](#8.4.3)
183
+
*[8.4.4 Dynamic Property Declarations](#8.4.4)
181
184
*[8.5 Index Member Declarations](#8.5)
182
185
*[8.6 Code Generation](#8.6)
183
186
*[8.6.1 Classes Without Extends Clauses](#8.6.1)
@@ -786,9 +789,94 @@ The '*( Modified )*' annotation indicates that an existing grammar production is
786
789
787
790
Similar to the ECMAScript grammar, if the phrase "*[no LineTerminator here]*" appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is not a match if a *LineTerminator* occurs in the input stream at the indicated position.
788
791
789
-
## <aname="2.2"/>2.2 Reserved Words
792
+
## <aname="2.2"/>2.2 Names
790
793
791
-
*TODO: Include [list of reserved words](https://github.com/Microsoft/TypeScript/issues/2536)*.
794
+
A core purpose of the TypeScript compiler is to track the named entities in a program and validate that they are used according to their designated meaning. Names in TypeScript can be written in several ways, depending on context. Specifically, a name can be written as
795
+
796
+
* an *IdentifierName*,
797
+
* a *StringLiteral* in a property name,
798
+
* a *NumericLiteral* in a property name, or
799
+
* a *ComputedPropertyName* that denotes a well-known symbol ([2.2.3](#2.2.3)).
800
+
801
+
Most commonly, names are written to conform with the *Identifier* production, which is any *IdentifierName* that isn't a reserved word.
802
+
803
+
### <aname="2.2.1"/>2.2.1 Reserved Words
804
+
805
+
The following keywords are reserved and cannot be used as an *Identifier*:
806
+
807
+
```TypeScript
808
+
breakcasecatchclass
809
+
constcontinuedebuggerdefault
810
+
deletedoelseenum
811
+
exportextendsfalsefinally
812
+
forfunction if import
813
+
in instanceof new null
814
+
return super switch this
815
+
throw true try typeof
816
+
var void while with
817
+
```
818
+
819
+
The following keywords cannot be used as identifiers in strict mode code, but are otherwise not restricted:
820
+
821
+
```TypeScript
822
+
implements interface let package
823
+
private protected public static
824
+
yield
825
+
```
826
+
827
+
The following keywords cannot be used as user defined type names, but are otherwise not restricted:
828
+
829
+
```TypeScript
830
+
any boolean number string
831
+
symbol
832
+
```
833
+
834
+
The following keywords have special meaning in certain contexts, but are valid identifiers:
835
+
836
+
```TypeScript
837
+
abstract as async await
838
+
constructor declare from get
839
+
is module namespace of
840
+
require set type
841
+
```
842
+
843
+
### <aname="2.2.2"/>2.2.2 Property Names
844
+
845
+
The *PropertyName* production from the ECMAScript grammar is reproduced below:
ECMAScript6permitsobjectliteralsandclassestodeclarememberswithcomputedpropertynames. Acomputedpropertynamespecifiesanexpressionthatcomputestheactualpropertynameatrun-time. Becausethefinalpropertynameisn't known at compile-time, TypeScript can only perform limited checks for entities declared with computed property names. However, a subset of computed property names known as ***well-known symbols*** can be used anywhere a *PropertyName* is expected, including property names within types. A computed property name is a well-known symbol if it is of the form
*TODO: [Computed names](https://github.com/Microsoft/TypeScript/issues/1082) and [Symbols](https://github.com/Microsoft/TypeScript/pull/1978)*.
927
-
928
-
Computed names of the form `[Symbol.XXX]` are called well known symbols. Well known symbols are treated like special identifiers.
929
-
930
-
A declaration that specifies a computed name that isn't well known doesn't introduce a property in its containing type. However, if the containing type has an indexer, the type of the property will be included in the union type for the indexer.
931
-
932
1012
<br/>
933
1013
934
1014
# <aname="3"/>3 Types
@@ -1707,7 +1787,7 @@ Here, 'g' and 'g.x' have the same recursive type, and likewise 'h' and 'h()' hav
1707
1787
1708
1788
## <aname="3.9"/>3.9 Specifying Members
1709
1789
1710
-
The members of an object type literal (section [3.8.3](#3.8.3)) are specified as a combination of property, call, construct, index, and method signatures.
1790
+
The members of an object type literal (section [3.8.3](#3.8.3)) are specified as a combination of property, call, construct, index, and method signatures.
1711
1791
1712
1792
### <aname="3.9.1"/>3.9.1 Property Signatures
1713
1793
@@ -1716,17 +1796,10 @@ A property signature declares the name and type of a property member.
The *PropertyName* production, reproduced above from the ECMAScript grammar, permits a property name to be any identifier (including a reserved word), a string literal, or a numeric literal. String literals can be used to give properties names that are not valid identifiers, such as names containing blanks. Numeric literal property names are equivalent to string literal property names with the string representation of the numeric literal, as defined in the ECMAScript specification.
1728
-
1729
-
The *PropertyName* of a property signature must be unique within its containing type. If the property name is followed by a question mark, the property is optional. Otherwise, the property is required.
1802
+
The *PropertyName* ([2.2.2](#2.2.2)) of a property signature must be unique within its containing type, and must denote a well-known symbol if it is a computed property name ([2.2.3](#2.2.3)). If the property name is followed by a question mark, the property is optional. Otherwise, the property is required.
1730
1803
1731
1804
If a property signature omits a *TypeAnnotation*, the Any type is assumed.
1732
1805
@@ -1903,7 +1976,7 @@ A method signature is shorthand for declaring a property of a function type.
If the identifier is followed by a question mark, the property is optional. Otherwise, the property is required. Only object type literals and interfaces can declare optional properties.
1979
+
If the *PropertyName* is a computed property name ([2.2.3](#2.2.3)), it must specify a well-known symbol. If the *PropertyName* is followed by a question mark, the property is optional. Otherwise, the property is required. Only object type literals and interfaces can declare optional properties.
1907
1980
1908
1981
A method signature of the form
1909
1982
@@ -2393,6 +2466,12 @@ If a get accessor is declared for a property, the return type of the get accesso
2393
2466
2394
2467
When an object literal is contextually typed by a type that includes a string index signature, the resulting type of the object literal includes a string index signature with the union type of the types of the properties declared in the object literal, or the Undefined type if the object literal is empty. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature, the resulting type of the object literal includes a numeric index signature with the union type of the types of the numerically named properties (section [3.9.4](#3.9.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties.
2395
2468
2469
+
If the *PropertyName* of a property assignment is a computed property name that doesn't denote a well-known symbol ([2.2.3](#2.2.3)), the construct is considered a ***dynamic property assignment***. The following rules apply to dynamic property assignments:
2470
+
2471
+
* A dynamic property assignment does not introduce a property in the type of the object literal.
2472
+
* The property name expression of a dynamic property assignment must be of type Any or the String, Number, or Symbol primitive type.
2473
+
* The name associated with a dynamic property assignment is considered to be a numeric property name if the property name expression is of type Any or the Number primitive type.
2474
+
2396
2475
## <a name="4.6"/>4.6 Array Literals
2397
2476
2398
2477
An array literal
@@ -4546,6 +4625,14 @@ A static member accessor declaration declares a property in the constructor func
4546
4625
4547
4626
Get and set accessors are emitted as calls to 'Object.defineProperty' in the generated JavaScript, as described in section [8.6.1](#8.6.1).
If the *PropertyName* of a property member declaration is a computed property name that doesn't denote a well-known symbol ([2.2.3](#2.2.3)), the construct is considered a ***dynamic property declaration***. The following rules apply to dynamic property declarations:
4631
+
4632
+
* A dynamic property declaration does not introduce a property in the class instance type or constructor function type.
4633
+
* The property name expression of a dynamic property assignment must be of type Any or the String, Number, or Symbol primitive type.
4634
+
* The name associated with a dynamic property declarations is considered to be a numeric property name if the property name expression is of type Any or the Number primitive type.
4635
+
4549
4636
## <a name="8.5"/>8.5 Index Member Declarations
4550
4637
4551
4638
An index member declaration introduces an index signature (section [3.9.4](#3.9.4)) in the class instance type.
@@ -4805,6 +4892,8 @@ The body of an enum declaration defines zero or more enum members which are the
4805
4892
  *EnumValue:*
4806
4893
   *AssignmentExpression*
4807
4894
4895
+
The *PropertyName* of an enum member cannot be a computed property name ([2.2.3](#2.2.3)).
4896
+
4808
4897
Enum members are either ***constant members*** or ***computed members***. Constant members have known constant values that are substituted in place of references to the members in the generated JavaScript code. Computed members have values that are computed at run-time and not known at compile-time. No substitution is performed for references to computed members.
0 commit comments