Skip to content

Narrowing by checking for existence of key leads to never. #38608

Description

TypeScript Version: 3.9.2

Search Terms:
instanceof narrow derived

Code

classCustomErrorextendsError{extra: string='hello'}consterror: Error=newCustomError()if('extra'inerror){// code path reached at runtimeerror// type: never}else{// code path not reached at runtimeerror// type: Error}

Expected behavior:
error inside the if block is still of type Error

Actual behavior:
error inside the if block is of type never

Playground Link:https://www.typescriptlang.org/play?#code/MYGwhgzhAEDCCuEAuB7AtgUQE5ZV6ApgB5IEB2AJjNrvgN6ElZgBc0yWAlmQObQC80AOQALAiBAoh0AL4AoYCjLJCOPGxp4B0MgQDucRKkxqsACgCUczgDNoZocSTNp3VbQvQ6c6L-daAegDoJABPAAcCNl0ANwIsORlCEAgCLx8-eNpoIJCIqOhNBJkgA

Related Issues:
None that seemed to match.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions