Skip to content

Narrowing does not work for variables typed with type parameters #6445

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
interface Base { b }
interface Derived extends Base { d }

declare function isDerived(x: Base): x is Derived;

function f<T extends Base>(x: T, y: T) {
    if (isDerived(x) && isDerived(y)) {
        return x.d === y.d;
    }

    return false;
}

Currently, this errors because both x and y still have type T, so they are missing the d property.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions