Closed
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
.