Type guard/Equality narrowing doesn't work on "any" #54239
Labels
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Bug Report
π Search Terms
type guard equality narrowing strict equal equality
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/FAMwrgdgxgLglgewgAgEYEMBOAKZWDmAXHhAJ7ICUyA3sMvcnCMrgcgLyfIRgA2vlGnQYjMAUxhhMKAgG5h9AL7AFjZq0z4OXEOl4BnMYNojREqTM3yRy5SqA
π» Code
π 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 ofany
it works perfectly fine. I think adjusting this, so it works forany
too, isn't too far fetched.The text was updated successfully, but these errors were encountered: