Unions and intersections of type predicates produce wrong type
See original GitHub issueTypeScript Version: 2.5.0-dev.20170803
Code
type Foo = typeof ts.isDoStatement | typeof ts.isWhileStatement;
Expected behavior:
Resulting type should be (node: ts.Node) => node is (ts.DoStatement | ts.WhileStatement)
Actual behavior:
Resulting type is (node: ts.Node) => node is ts.DoStatement
It seems to just take the first one.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Handbook - Unions and Intersection Types - TypeScript
Intersection and Union types are one of the ways in which you can compose types.
Read more >Typescript type predicates not differentiating between ...
But I'm facing an issue where each predicate catches both types when applied to a union type. Here is an example: Playground Link....
Read more >Union and intersection contracts are hard, actually - Tweag
But contracts are not exactly predicates, and this subtle difference makes the implementation of general unions ( or ) and intersections ...
Read more >Narrowing 'this' type with multiple type predicates makes ...
Looks like unions need to include private/protected members in their property set if every union element contains them.
Read more >Chapter 4: Union and Intersection Types - HackMD
Let's first create a TechEventBase type that contains all properties that are the same in all three event types. type TechEventBase = {...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I knew using “type guards” like that wasn’t quite right. 😂
It appears to just grab the first type predicate and ignore the rest.
Here is a self-contained repro (2.5.0-dev.20170808)
Intersecting type predicates seems to have the same result, only the first signature is considered.