Skip to content

TS 3.2.0-rc seems to forget union type refinements more eagerly #28568

Description

TypeScript Version: 3.2.0-rc

Search Terms:
refinement

Code

(EDIT: incorrect reproduction, see correct example at #28568 (comment))

functiontest(x: {type: 'a';body: string|null}|{type: 'b';body: number|null}): string{if(x.body===null){return'null'}x.body.toString()// okif(x.type==='a'){returnx.body.toString()// x.body may be null}else{returnx.body.toString()// x.body may be null}}

Expected behavior:
The refinement of x.body should persist (it does in 3.1)

Actual behavior:
TS forgets that it has already refined x.body to be not null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions