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
Copy file name to clipboardExpand all lines: doc/spec.md
+14-14
Original file line number
Diff line number
Diff line change
@@ -102,9 +102,9 @@ TypeScript is a trademark of Microsoft Corporation.
102
102
*[4.14.5 The void Operator](#4.14.5)
103
103
*[4.14.6 The typeof Operator](#4.14.6)
104
104
*[4.15 Binary Operators](#4.15)
105
-
*[4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1)
105
+
*[4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1)
106
106
*[4.15.2 The + operator](#4.15.2)
107
-
*[4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.15.3)
107
+
*[4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.15.3)
108
108
*[4.15.4 The instanceof operator](#4.15.4)
109
109
*[4.15.5 The in operator](#4.15.5)
110
110
*[4.15.6 The && operator](#4.15.6)
@@ -1088,7 +1088,7 @@ Since a type parameter represents a multitude of different type arguments, type
1088
1088
1089
1089
### <aname="3.4.1"/>3.4.1 Type Parameter Lists
1090
1090
1091
-
Class, interface, and function declarations may optionally include lists of type parameters enclosed in < and > brackets. Type parameters are also permitted in call signatures of object, function, and constructor type literals.
1091
+
Class, interface, and function declarations may optionally include lists of type parameters enclosed in < and > brackets. Type parameters are also permitted in call signatures of object, function, and constructor type literals.
a type reference of the form ‘G<A, B>’ places no requirements on ‘A’ but requires ‘B’ to be assignable to ‘Function’.
1152
+
a type reference of the form ‘G<A, B>’ places no requirements on ‘A’ but requires ‘B’ to be assignable to ‘Function’.
1153
1153
1154
1154
The process of substituting type arguments for type parameters in a generic type or generic signature is known as ***instantiating*** the generic type or signature. Instantiation of a generic type or signature can fail if the supplied type arguments do not satisfy the constraints of their corresponding type parameters.
1155
1155
@@ -1354,13 +1354,13 @@ Object type literals are the primary form of type literals and are described in
1354
1354
1355
1355
As the table above illustrates, an array type literal is shorthand for a reference to the generic interface type ‘Array’ in the global module, a function type literal is shorthand for an object type containing a single call signature, and a constructor type literal is shorthand for an object type containing a single construct signature. Note that function and constructor types with multiple call or construct signatures cannot be written as function or constructor type literals but must instead be written as object type literals.
1356
1356
1357
-
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an A*rrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type
1357
+
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an A*rrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type
1358
1358
1359
1359
```TypeScript
1360
1360
() =>string[]
1361
1361
```
1362
1362
1363
-
denotes a function returning a string array, not an array of functions returning string. The latter can be expressed using ‘Array<T>’ notation
1363
+
denotes a function returning a string array, not an array of functions returning string. The latter can be expressed using ‘Array<T>’ notation
1364
1364
1365
1365
```TypeScript
1366
1366
Array<() =>string>
@@ -1833,7 +1833,7 @@ interface List<T> {
1833
1833
}
1834
1834
```
1835
1835
1836
-
‘List<T>’ has a member ‘owner’ of type ‘List<List<T>>’, which has a member ‘owner’ of type ‘List<List<List<T>>>’, which has a member ‘owner’ of type ‘List<List<List<List<T>>>>’ and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome.
1836
+
‘List<T>’ has a member ‘owner’ of type ‘List<List<T>>’, which has a member ‘owner’ of type ‘List<List<List<T>>>’, which has a member ‘owner’ of type ‘List<List<List<List<T>>>>’ and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome.
1837
1837
1838
1838
## <a name="3.9"/>3.9 Widened Types
1839
1839
@@ -2247,7 +2247,7 @@ A signature is said to be an ***applicable signature*** with respect to an argum
2247
2247
2248
2248
### <aname="4.12.2"/>4.12.2TypeArgumentInference
2249
2249
2250
-
Givenasignature<*T<sub>1</sub>* , *T<sub>2</sub>* , … , *T<sub>n</sub>*> ( *p<sub>1</sub>* : *P<sub>1</sub>* , *p<sub>2</sub>* : *P<sub>2</sub>* , … , *p<sub>m</sub>* : *P<sub>m</sub>* ), whereeachparametertype*P*referenceszeroormoreofthetypeparameters *T*, and an argument list ( *e<sub>1</sub>* , *e<sub>2</sub>* , … , *e<sub>m</sub>* ), the task of type argument inference is to find a set of type arguments *A<sub>1</sub>*…*A<sub>n</sub>* to substitute for *T<sub>1</sub>*…*T<sub>n</sub>* such that the argument list becomes an applicable signature.
2250
+
Givenasignature<*T<sub>1</sub>* , *T<sub>2</sub>* , … , *T<sub>n</sub>*> ( *p<sub>1</sub>* : *P<sub>1</sub>* , *p<sub>2</sub>* : *P<sub>2</sub>* , … , *p<sub>m</sub>* : *P<sub>m</sub>* ), whereeachparametertype*P*referenceszeroormoreofthetypeparameters *T*, and an argument list ( *e<sub>1</sub>* , *e<sub>2</sub>* , … , *e<sub>m</sub>* ), the task of type argument inference is to find a set of type arguments *A<sub>1</sub>*…*A<sub>n</sub>* to substitute for *T<sub>1</sub>*…*T<sub>n</sub>* such that the argument list becomes an applicable signature.
2251
2251
2252
2252
Theinferredtypeargument for a particular type parameter is determined from a set of candidate types. Given a type parameter *T*, let *C* denote the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the set of candidate types *T*. Then,
2253
2253
@@ -2337,7 +2337,7 @@ The inclusion of type arguments in the *Arguments* production (section [4.12](#4
2337
2337
f(g<A, B>(7));
2338
2338
```
2339
2339
2340
-
couldbeinterpretedasacallto ‘f’ withtwoarguments, ‘g<A’ and ‘B> (7)’. Alternatively, itcouldbeinterpretedasacallto ‘f’ withoneargument, whichisacalltoagenericfunction ‘g’ with two type arguments and one regular argument.
2340
+
couldbeinterpretedasacallto ‘f’ withtwoarguments, ‘g<A’ and ‘B> (7)’. Alternatively, itcouldbeinterpretedasacallto ‘f’ withoneargument, whichisacalltoagenericfunction ‘g’ with two type arguments and one regular argument.
Thesubsectionsthatfollowspecifythecompile-timeprocessingrulesofthebinaryoperators. Ingeneral, iftheoperandsofabinaryoperatordonotmeetthestatedrequirements, acompile-timeerroroccursandtheresultoftheoperationdefaultstotypeany in further processing. Tables that summarize the compile-time processing rules for operands of the Any type, the Boolean, Number, and String primitive types, and all object types and type parameters (the Object column in the tables) are provided.
TheseoperatorsrequiretheiroperandstobeoftypeAny, the Number primitive type, or an enum type. Operands of an enum type are treated as having the primitive type Number. If one operand is the `null` or `undefine``d` value, it is treated as having the type of the other operand. The result is always of the Number primitive type.
2455
2455
@@ -2483,7 +2483,7 @@ var s = getValue() + "";
2483
2483
2484
2484
Theexampleaboveconvertstheresultof ‘getValue()’ toastringifitisn’tastringalready. Thetypeinferred for ‘s’ is the String primitive type regardless of the return type of ‘getValue’.
Theseoperatorsrequireoneoperandtypeto be identical to or a subtype of the other operand type. The result is always of the Boolean primitive type.
2489
2489
@@ -4398,7 +4398,7 @@ The source elements permitted in a TypeScript implementation source file are a s
4398
4398
4399
4399
Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript code in an adjunct manner. They are entirely optional but enable the TypeScript compiler and tools to provide better verification and assistance when integrating existing JavaScript code and libraries in a TypeScript application.
4400
4400
4401
-
Implementation and declaration source files that contain no import or export declarations form the single ***global module***. Entities declared in the global module are in scope everywhere in a program. Initialization order of the source files that make up the global module ultimately depends on the order in which the generated JavaScript files are loaded at run-time (which, for example, may be controlled by <script/> tags that reference the generated JavaScript files).
4401
+
Implementation and declaration source files that contain no import or export declarations form the single ***global module***. Entities declared in the global module are in scope everywhere in a program. Initialization order of the source files that make up the global module ultimately depends on the order in which the generated JavaScript files are loaded at run-time (which, for example, may be controlled by <script/> tags that reference the generated JavaScript files).
4402
4402
4403
4403
Implementation and declaration source files that contain at least one external import declaration, export assignment, or top-level exported declaration are considered separate ***external modules***. Entities declared in an external module are in scope only in that module, but exported entities can be imported into other modules using import declarations. Initialization order of external modules is determined by the module loader being and is not specified by the TypeScript language. However, it is generally the case that non-circularly dependent modules are automatically loaded and initialized in the correct order.
4404
4404
@@ -4408,7 +4408,7 @@ External modules can additionally be declared using *AmbientExternalModuleDeclar
4408
4408
4409
4409
The TypeScript compiler automatically determines a source file’s dependencies and includes those dependencies in the program being compiled. The determination is made from “reference comments” and external import declarations as follows:
4410
4410
4411
-
* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file.
4411
+
* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file.
4412
4412
* An external import declaration that specifies a relative external module name (section [11.2.1](#11.2.1)) resolves the name relative to the directory of the containing source file. If a source file with the resulting path and file extension ‘.ts’ exists, that file is added as a dependency. Otherwise, if a source file with the resulting path and file extension ‘.d.ts’ exists, that file is added as a dependency.
4413
4413
* An external import declaration that specifies a top-level external module name (section [11.2.1](#11.2.1)) resolves the name in a host dependent manner (typically by resolving the name relative to a module name space root or searching for the name in a series of directories). If a source file with extension ‘.ts’ or ‘.d.ts’ corresponding to the reference is located, that file is added as a dependency.
4414
4414
@@ -4619,7 +4619,7 @@ The special
4619
4619
4620
4620
# <a name="12"/>12 Ambients
4621
4621
4622
-
Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist “ambiently” and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag.
4622
+
Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist “ambiently” and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag.
0 commit comments