Microsoft/TypeScript

TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.

Offen

#27.910 geöffnet am 15.10.2018

 (14 Kommentare) (8 Reaktionen) (0 zugewiesene Personen)TypeScript (13.395 Forks)batch import
Domain: Error MessagesExperience EnhancementGood First IssueHelp WantedSuggestion

Repository-Metriken

Stars
 (108.860 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

TypeScript Version: 3.2.0-dev.20181011

Search Terms: TS2367

Code

abstract class Base<T> {
    get Item(): T { return null }
}

class Child extends Base<Item> {
    constructor(public data: any) { super() }
}

interface Item { }
declare type Constructor<T> = new (data: any) => Base<T>

function func<T>(constructor: Constructor<T>): void {
    // TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.
    if (constructor === Child) {
        // do something
    }
    new constructor(null)
}

func(Child) // No errors

Expected behavior:

Compiles without errors.

Actual behavior:

test.ts:14:9 - error TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.

14     if (constructor === Child) {
           ~~~~~~~~~~~~~~~~~~~~~

Playground Link

Related Issues: #25642

Contributor Guide