microsoft / microsoft/TypeScript
types 'new (...args: any) => E' and wrapper types constructor for primitive types have no 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: 3.8.3
Code
class TreeSet<E> {
constructor(elementType: new(...args: any) => E) {
if (elementType === Number) { //This condition will always return 'false' since the types 'new (...args: any) => E' and 'NumberConstructor' have no overlap.(2367)
console.log("hello")
}
}
}
new TreeSet(Number)
Actual behavior:
The error is prompted at compile time "This condition will always return 'false' since the types 'new (...args: any) => E' and 'NumberConstructor' have no overlap.(2367)" but compiled code actually runs correctly.
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
Start with the TypeScript 3.8.3 playground reproduction and the TreeSet constructor comparison shown in the issue. Trace the compiler's diagnostic for the comparison between the generic constructor type and NumberConstructor, then verify the behavior against the supplied example and ensure the false-positive diagnostic no longer appears.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100