Skip to content

instanceof Error typeguard not functioning #1938

Closed
@basarat

Description

@basarat

Wonder if this is something that should work. I think it should:

    try {
         throw new Error('awesome');
    } catch (ex) {
        if (ex instanceof Error) {
            console.log(ex.foo);  // compiles. Should be error
        }
    }

The reason is that ex is still of type any. I suspect its in the spec that instanceof guard will not work on type any (I haven't checked).

image

Would be great if we could have this though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions