Closed
Description
π Search Terms
Type Narrowing
Boolean
Undefined
π Version & Regression Information
Version: 5.6.3
Regression: Unknown
β― Playground Link
π» Code
function testOne(foo: string | undefined) {
const thing = !!foo;
if(thing) {
// Foo type is String
return foo.charAt(0);
}
return 'undefined'
}
function testTwo(foo: string | undefined) {
const thing: boolean = !!foo;
if(thing) {
// Foo type is string | undefined
return foo.charAt(0);
}
return 'undefined'
}
π Actual behavior
foo
is typed as string | undefined
if thing
has explicit type of boolean
π Expected behavior
foo
should be typed as string
if thing
has type of boolean
just like if thing
's type is inferred
Additional information about the issue
No response