Microsoft/TypeScript

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

Open

#27 910 ouverte le 15 oct. 2018

Voir sur GitHub
 (14 commentaires) (8 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Domain: Error MessagesExperience EnhancementGood First IssueHelp WantedSuggestion

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 2j 7h) (8 PRs mergées en 30 j)

Description

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

Guide contributeur