Commit graph

35 commits

Author SHA1 Message Date
Tingan Ho
b1a8a5fe66 Addresses CR feedback 2015-06-07 22:16:09 +08:00
Tingan Ho
487dff564f Fixes CR feedback 2015-06-06 13:59:19 +08:00
Tingan Ho
fa9a914648 Adds error for non-return positioned type predicates and changed parse type predicate logic 2015-06-05 16:36:02 +08:00
Tingan Ho
19e725636e Adds PR feedback and removed references to typeguard (class) methods 2015-06-04 19:31:16 +08:00
Tingan Ho
b7d1df68fb Adds type guard methods 2015-06-03 16:58:56 +08:00
Tingan Ho
f8e2b99b6c Adds tests 2015-06-03 16:58:56 +08:00
Mohamed Hegazy
8b43b3d18c Update test 2015-05-06 20:18:32 -07:00
Mohamed Hegazy
5e94ce65ed Merge branch 'typeguardsByConstructorSigniture' of https://github.com/vvakame/TypeScript into vvakame-typeguardsByConstructorSigniture 2015-05-06 12:44:45 -07:00
vvakame
776f390786 PR feedback 2015-05-06 21:18:15 +09:00
vvakame
ab10d509f5 support instantiate signature, it has type parameters. 2015-05-02 15:27:06 +09:00
vvakame
35d6e98e98 type narrowing by constructor signiture of interface 2015-04-30 23:12:35 +09:00
Yui T
ac8ae27139 Address code review 2015-04-16 20:09:03 -07:00
Yui T
8899d5f056 Add additional tests for typeguard for class or object property 2015-04-15 16:55:59 -07:00
Anders Hejlsberg
7f63180b64 Adding tests 2015-01-24 17:23:22 -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
Anders Hejlsberg
968a56924f Type guard narrows type any in a primitive type check 2015-01-08 14:27:39 -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
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