Commit graph

191 commits

Author SHA1 Message Date
Daniel Rosenwasser
bfe63cc4cb Merge pull request #1648 from Microsoft/contextualTypeParenthesizedExpressions
Contextually type parenthesized expressions
2015-01-14 14:52:07 -08:00
Yui T
fdadd3c18e Fix narrow type for instanceOf and add testcases 2015-01-14 11:30:58 -08:00
Anders Hejlsberg
59e266de02 Improved handing of union types in type guards 2015-01-12 14:51:20 -08:00
Daniel Rosenwasser
cd246992ed Clarified comment in test. 2015-01-09 14:19:24 -08:00
Daniel Rosenwasser
f5f4e28f4f Fixed portion of test. 2015-01-08 16:53:26 -08:00
Daniel Rosenwasser
d5f02813f0 Added tests for contextual typing on parenthesized expressions, added case for tagged templates. 2015-01-08 16:39:47 -08:00
Anders Hejlsberg
40dc1341ab Merge pull request #1621 from Microsoft/narrowingOfAny
Type guard narrows type any in a primitive type check
2015-01-08 15:57:15 -08:00
Anders Hejlsberg
968a56924f Type guard narrows type any in a primitive type check 2015-01-08 14:27:39 -08:00
Daniel Rosenwasser
1f6cd941fd Changed tests to error when actual contextual typing is broken. 2014-12-15 17:09:56 -08:00
Daniel Rosenwasser
0263d60071 Split contextual typing test for substitution expressions into two tests. 2014-12-15 16:14:35 -08:00
Daniel Rosenwasser
b65a422c7a Fixed contextual typing for tagged template expressions. 2014-12-15 14:11:21 -08:00
Anders Hejlsberg
35adeb8363 Addressing CR feedback 2014-12-10 14:44:31 -08:00
Anders Hejlsberg
98c9f75e21 Adding test case 2014-12-10 14:41:37 -08:00
Anders Hejlsberg
2876ba6a6c Addressing CR feedback 2014-12-10 14:25:02 -08:00
Anders Hejlsberg
37b5c74b93 Adding test case 2014-12-10 10:17:48 -08:00
Sheetal Nandi
ab4ccb3a1c Merge branch 'master' into unionTypeConformance 2014-11-21 01:33:13 -08:00
Anders Hejlsberg
df544a687c Addressing CR feedback 2014-11-14 13:36:09 -08:00
Anders Hejlsberg
91b97009f0 Modifying tests and accepting new baselines 2014-11-14 10:42:31 -08:00
Sheetal Nandi
152c77cd2a Add test cases for typeof x == s and typeof x != s form of typeguard which has no effect on narrowing type 2014-11-12 12:49:29 -08:00
Sheetal Nandi
45ca9d285f Add test case for instance of type guard with interface with prototype property 2014-11-12 12:36:06 -08:00
Sheetal Nandi
52a8560298 Typeguards of form !expr
•	A type guard of the form !expr
o	when true, narrows the type of x by expr when false, or
o	when false, narrows the type of x by expr when true.
2014-11-06 13:04:43 -08:00
Sheetal Nandi
c9a03dc659 Typeguards of form expr1 || expr2
•	A type guard of the form expr1 || expr2
o	when true, narrows the type of x to T1 | T2, where T1 is the type of x narrowed by expr1 when true, and T2 is the type of x narrowed by expr1 when false and then by expr2 when true, or
o	when false, narrows the type of x by expr1 when false and then by expr2 when false.
2014-11-06 13:04:40 -08:00
Sheetal Nandi
486d37ec90 TypeGuard of for expr1 && expr2
•	A type guard of the form expr1 && expr2
o	when true, narrows the type of x by expr1 when true and then by expr2 when true, or
o	when false, narrows the type of x to T1 | T2, where T1 is the type of x narrowed by expr1 when false, and T2 is the type of x narrowed by expr1 when true and then by expr2 when false.
2014-11-06 13:04:37 -08:00
Sheetal Nandi
7ebf5371a5 Test cases for typeguards of form typeof x === s and typeof x !== s
•	A type guard of the form typeof x === s, where s is a string literal with the value ‘string’, ‘number’, or ‘boolean’,
o	when true, narrows the type of x to the given primitive type, or
o	when false, removes the primitive type from the type of x.
•	A type guard of the form typeof x === s, where s is a string literal with any value but ‘string’, ‘number’, or ‘boolean’,
o	when true, removes the primitive types string, number, and boolean from the type of x, or
o	when false, has no effect on the type of x.
•	A type guard of the form typeof x !== s, where s is a string literal,
o	when true, narrows the type of x by typeof x === s when false, or
o	when false, narrows the type of x by typeof x === s when true.
2014-11-06 13:04:34 -08:00
Sheetal Nandi
5961ed7154 Test typeguard of form instance of
•	A type guard of the form x instanceof C, where C is of a subtype of the global type ‘Function’ and C has a property named ‘prototype’
o	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
o	when false, has no effect on the type of x.
2014-11-06 13:04:30 -08:00
Sheetal Nandi
2fecc132ab Tests for typeguards allowed on variables and parameters only
From spec:
Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties
2014-11-06 13:04:27 -08:00
Sheetal Nandi
33cdc2f876 Type guards in || operator
•	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.
2014-11-06 13:04:24 -08:00
Sheetal Nandi
11912e8fde TypeGuards in right operand of && operation
•	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.
2014-11-06 13:04:21 -08:00
Sheetal Nandi
55952af304 Tests for conditional expression typeguards
•	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 expression contains no assignments to the variable or parameter.
•	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 expression contains no assignments to the variable or parameter.
2014-11-06 13:04:18 -08:00
Sheetal Nandi
4b3d603f24 Test cases for typeguards are scoped at function /module block 2014-11-06 13:04:14 -08:00
Sheetal Nandi
2088a89223 Test cases to make sure typeguard is defeated in case of function calls
From spec:
Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable.
2014-11-06 13:04:11 -08:00
Sheetal Nandi
e79bec5cbf TypeGuards narrow types in if statement works per spec:
The type of a variable or parameter is narrowed in the following situations:
•	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 if statement contains no assignments to the variable or parameter.
•	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 if statement contains no assignments to the variable or parameter.
2014-11-06 13:04:08 -08:00
Sheetal Nandi
24ebc750c0 Tests for Conditional operator can generate union type 2014-11-04 13:18:43 -08:00
Sheetal Nandi
b66cd9b0fc Results of || operation produces union type 2014-11-04 13:18:40 -08:00
Anders Hejlsberg
10a7e6ba70 Fixing in, for...in, and instanceof with union type operands 2014-10-22 16:57:43 -07:00
Anders Hejlsberg
fc842b177e Merge branch 'master' into unionTypes
Conflicts:
	src/compiler/checker.ts
	src/compiler/types.ts
	src/services/services.ts
	tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt
	tests/baselines/reference/bestCommonTypeOfTuple.types
	tests/baselines/reference/bestCommonTypeOfTuple2.types
	tests/baselines/reference/castingTuple.errors.txt
	tests/baselines/reference/contextualTypeWithTuple.errors.txt
	tests/baselines/reference/genericCallWithTupleType.errors.txt
	tests/baselines/reference/indexerWithTuple.types
	tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt
2014-10-13 12:37:34 -07:00
Dan Quirk
bacb9d0b22 Test updates from union changes 2014-10-10 14:41:14 -07:00
ChrisBubernak
15c5c77704 Fixing tests and baselines 2014-10-08 11:11:36 -07:00
Chris Bubernak
c77135d3d9 Removed Numeric members from a bunch of tests
-in these tests it wasn't really in the spirit of the tests for them to be there
-also removed a test that no longer made sense
2014-10-06 16:14:45 -07:00
Jason Freeman
6fb3c34681 Conformance coverage for spec change #589 2014-09-05 18:44:49 -07:00
Mohamed Hegazy
214df64e28 Add snapshot of compiler sources 2014-07-12 17:30:19 -07:00