Control flow analysis for dependent parameters only works when checking against literals #55766
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
narrow, parameters, typeof
π Version & Regression Information
It never worked for
typeof
/asserts
checks since the feature introduction in #47190; it's been mentioned here:#47190 (comment)
β― Playground Link
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAZmAMgSygUwE4EMA2AuGACgDpSsMBzCAgbQAMs6AaGMAVwFsAjTAXRgA+Mel2YxoGZGAq8AlDAC8APhgA3EMgAmiolhZd5ymAG8AUDBjI4uxQoUwARFgfyzFi6EggcaYjhAUhAYA3ObuAPTh7tHuAHoA-GEAvqYppp7Q8GAAghAQmFAEJGSU1MIMYuzcfILloiwSUjKGKupaOoR6MAaKKm6W1oTIENmdsq5hHuAQ3r7+gSGTMJExMQnJqenTsAgAKgCeAA5oIHBFpMTkVLRVPBgstzVCNI3SDVCS0nK9ahra9p19C0TGErEQoEcTtYsLZ7A5HhgXCDohlZn4AkFZKFoitVnFEhYUmk4GwwMAoMhwJYRoRVLgCKSANZgEAAdzAsgIdJw1JgFWRMAwaCgbAwYBgHzYaFCKSAA
π» Code
π Actual behavior
Both
fnAssert
andfnTypeof
are unable to get TS to recognizeb
as its narrowed type (number
). Only ifa
is checked against a literal does the narrowing works.π Expected behavior
The
b
parameter should be narrowed tonumber
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: