Closed
Description
Whilst looking at @RyanCavanaugh's example code in this comment I noticed odd narrowing behaviour depending how the type guards are arranged. Is this expected?
function isActuallyThing(x: any): x is Thing {
return /* my special way of determining Thingness */
}
function doSomething(x: Thing|string) {
if (typeof x === 'string') {
//...
} else if (isActuallyThing(x)) {
//...
} else {
x // type of x here is Thing <== WHY NOT Thing|string?
}
}
function sameButDifferent(x: Thing|string) {
if (isActuallyThing(x)) {
//...
}
else if (typeof x === 'string') {
//...
} else {
x // type of x here is Thing|string
}
}