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
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# TypeScript Language Specification
2
2
3
-
Version 1.3
3
+
Version 1.4
4
4
5
5
October, 2014
6
6
@@ -2928,17 +2928,17 @@ function foo(x: number | string) {
2928
2928
2929
2929
The type of a variable or parameter is narrowed in the following situations:
2930
2930
2931
-
* In the true branch statement of an ‘if’ statement, the type of a variable or parameter is *narrowed *by any type guard in the ‘if’ condition *when true*, provided the true branch statement contains no assignments to the variable or parameter.
2932
-
* In the false branch statement of an ‘if’ statement, the type of a variable or parameter is *narrowed *by any type guard in the ‘if’ condition *when false*, provided the false branch statement contains no assignments to the variable or parameter.
2933
-
* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed *by any type guard in the condition *when true*, provided the true expression contains no assignments to the variable or parameter.
2934
-
* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed *by any type guard in the condition *when false*, provided the false expression contains no assignments to the variable or parameter.
2935
-
* In the right operand of a && operation, the type of a variable or parameter is *narrowed *by any type guard in the left operand *when true*, provided the right operand contains no assignments to the variable or parameter.
2936
-
* In the right operand of a || operation, the type of a variable or parameter is *narrowed *by any type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter.
2931
+
* In the true branch statement of an ‘if’ statement, the type of a variable or parameter is *narrowed* by any type guard in the ‘if’ condition *when true*, provided the true branch statement contains no assignments to the variable or parameter.
2932
+
* In the false branch statement of an ‘if’ statement, the type of a variable or parameter is *narrowed* by any type guard in the ‘if’ condition *when false*, provided the false branch statement contains no assignments to the variable or parameter.
2933
+
* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when true*, provided the true expression contains no assignments to the variable or parameter.
2934
+
* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when false*, provided the false expression contains no assignments to the variable or parameter.
2935
+
* In the right operand of a && operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when true*, provided the right operand contains no assignments to the variable or parameter.
2936
+
* In the right operand of a || operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter.
2937
2937
2938
2938
A type guard is simply an expression that follows a particular pattern. The process of narrowing the type of a variable *x* by a type guard *when true* or *when false* depends on the type guard as follows:
2939
2939
2940
2940
* A type guard of the form `xinstanceofC`, where *C* is of a subtype of the global type ‘Function’ and *C* has a property named ‘prototype’
2941
-
* *when true*, narrows the type of *x* to the type of the ‘prototype’ property in *C* provided it is a subtype of the type of *x*, or
2941
+
* *when true*, narrows the type of *x* to the type of the ‘prototype’ property in *C* provided it is a subtype of the type of *x*, or
2942
2942
* *when false*, has no effect on the type of *x*.
2943
2943
* A type guard of the form `typeofx===s`, where *s* is a string literal with the value ‘string’, ‘number’, or ‘boolean’,
2944
2944
* *when true*, narrows the type of *x* to the given primitive type, or
@@ -2962,7 +2962,7 @@ A type guard is simply an expression that follows a particular pattern. The proc
2962
2962
2963
2963
A primitive type *P* is removed from a type *T* as follows:
2964
2964
2965
-
* If *T* is a union type *P* | *T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*, the result is the type* T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*.
2965
+
* If *T* is a union type *P* | *T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*, the result is the type *T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*.
2966
2966
* Otherwise, the result is *T*.
2967
2967
2968
2968
Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties. Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable.
0 commit comments