Incorrect error on legitimate type overlap
See original GitHub issueTypeScript Version: 4.1.0-dev-20201102
Search Terms:
This condition will always return ‘false’ since the types ‘X’ and ‘Y’ have no overlap.
Code
function fn<T>(t: T) {
return t === '' // error
}
fn('') // but here we pass it
Expected behavior:
It works when we extend unknown
. While this works on simple generics, it becomes inconvenient when the type parameter is nested deeper in a type structure.
function fn<T extends unknown>(t: T) {
return t === '' // works
}
fn('') // works
Actual behavior:
This condition will always return 'false' since the types 'T' and 'string' have no overlap.
Related issues https://github.com/microsoft/TypeScript/issues/27910
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
This condition will always return 'false' since the types have no ...
TypeScript Version: 3.0.0-dev.20180712 Error: This condition will always return 'false' since the types 'A' and 'I' have no overlap.
Read more >Fake Pivot overlap errors, How to fix them/tell the difference
Now I can see the real size of the Pivot table and either these are actually so large (due to data errors) that...
Read more >Type I & Type II Errors | Differences, Examples, Visualizations
In statistics, a Type I error is a false positive conclusion, while a Type II error is a false negative conclusion.
Read more >This condition will always return 'false' since the types '1' and ...
This condition will always return 'false' since the types '1' and '2' have no overlap. what am i doing wrong? .ts status: number;...
Read more >Type I and type II errors - Wikipedia
In statistical hypothesis testing, a type I error is the mistaken rejection of an actually true null hypothesis while a type II error...
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
That’s exactly what I’m complaining about.
I get that a generic
T
intersected withany
orunknown
yieldsT
.I’m pointing out the fact that we could safely narrow
T
with the type that sits on therhs
of the comparison operator.But @RyanCavanaugh seems to say that it’s not possible, and I would like to know why should we have such a limitation.
Another example:
A generic type parameter is comparable to the type of its constraint if a constraint was explicitly declared