Skip to content

Type predicates fail to remove subclasses from unions for assumeTrue=false. #10254

Closed
@sandersn

Description

@sandersn

@ahejlsberg you probably already know about this one but I thought I'd confirm:

interface Error {
    e
}
declare function isError(value: any): value is Error;
class CustomError extends Error { }
function narrowTest(value: number | CustomError) {
    if(isError(value)) {
        let result: CustomError = value;
    }
    else {
        let result: number = value; // error!
    }
}

Expected: narrowing to number in the else branch.
Actual: No narrowing: value: CustomError | number in the else branch, causing an error.

I found this in lodash on DefinitelyTyped.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions