-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 3.2.0-rc
Search Terms:
refinement
Code
(EDIT: incorrect reproduction, see correct example at #28568 (comment))
function test(x: { type: 'a'; body: string | null } | { type: 'b'; body: number | null }): string {
if (x.body === null) {
return 'null'
}
x.body.toString() // ok
if (x.type === 'a') {
return x.body.toString() // x.body may be null
} else {
return x.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
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug