Microsoft/TypeScript

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

Open

#27.910 geöffnet am 15. Okt. 2018

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

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 7h) (8 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