Open
Description
Bug Report
π Search Terms
type guard equality narrowing strict equal equality
π Version & Regression Information
- This is the behavior in every version I tried, and I found earlier issues (Number, enum, and boolean literal typesΒ #9407 and the PR that added this feature Number, enum, and boolean literal typesΒ #9407)
β― Playground Link
π» Code
function bar( arg: any ) {
if ( arg === null ) {
return arg;
}
if ( arg === false ) {
return arg;
}
}
π Actual behavior
arg should be null
/false
inside the if conditions
π Expected behavior
arg is any
The docs say this should work https://www.typescriptlang.org/docs/handbook/2/narrowing.html
When using unknown
instead of any
it works perfectly fine. I think adjusting this, so it works for any
too, isn't too far fetched.