microsoft / microsoft/TypeScript

types 'new (...args: any) => E' and wrapper types constructor for primitive types have no overlap

Open
#37,155 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: check: Control Flow
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.

Playground Link:
https://www.typescriptlang.org/play/?ssl=9&ssc=20&pln=1&pc=1#code/MYGwhgzhAEAqBOBTRBlRAXAPAUQHzQG8AoaU6YAewDsJ14BXYdC+ACkREQFtEr1YAngAdEALmhVEAd1YA6eWHgBzCOLBUBASmgBefNm3Eyx6AEsAZtHacefQSN06d0AHL0uAI0TxDJE-8oaCk5ZEAolVgAiAAsOMMjNP38AXyToVNSiSSk4JFQMVjdPb00gA

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.