narrowing in switch doesn't work with non-union types
See original GitHub issueclass A {
readonly kind = 'a';
}
type U = A; // <-- supposed to be a single case union
declare var u: U;
declare function never(never: never): never;
function fn() {
switch (u.kind) {
case 'a': return 1;
default: return never(u); // <-- u expected to be never, actually is A
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:12 (3 by maintainers)
Top Results From Across the Web
TypeScript 3.8.3 not narrowing union type in switch statement
I notice that from TS 4.3.5 and on, the type is narrowed the way I'd expect (the error disappears), but I can't change...
Read more >narrowing types via type guards and assertion functions - 2ality
The problem in this case is that, without narrowing, we can't access property .second of a value whose type is FirstOrSecond . The...
Read more >Malunions and Nonunions: Penn Medicine's Samir Mehta, MD ...
Four Factors for Fracture Healing. Typically, the reasons an injury did not properly heal can be narrowed down quickly. "Usually, the problem is ......
Read more >9 strategies for narrowing the gender pay gap | MoneyUnder30
Strategies to narrow the gender pay gap include promoting pay transparency, expanding paid family and medical leave, and improving work-life ...
Read more >Spinal Deformity: Adult Degenerative Scoliosis - Mayfield Clinic
Types of spinal deformities: a side-to-side curve is called scoliosis; ... Simply removing material from the spine can cause a problem down the...
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 FreeTop 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
Top GitHub Comments
interestingly narrowing works for single string literals, which is at very least looks inconsistent with this very issue
@RyanCavanaugh,
Can be useful when designing API that don’t have union initially, but later got it: