microsoft / microsoft/TypeScript
Incorrect error on legitimate type overlap
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the generic comparison in the TypeScript compiler using the provided code and Playground links, then compare it with the T extends unknown example. Investigate the type-overlap diagnostic and related issue #27910; done means the legitimate comparison no longer reports that it will always return false while invalid comparisons remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100