-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aliased Conditions with explicit type definition results in the "old" behavior #45469
Comments
This is mentioned explicitly in PR that implements feature (#44730 after first code block):
|
Thanks for pointing out that indeed it seems to be by design according to the PR, and there is probably a good technical reason for why it is like that. However I would argue that from a functional (the consuming developer) perspective it is unexpected (and even inconsistent) behavior. I.e. a type which is determined by the compiler (i.e. the boolean presented to the developer) and a type annotation of that same type, is in my opinion expected to behave identical. Imaging the following scenario:
If I recall correctly at some point (and maybe even still today) it was even suggested to use explicit type annotations as a way to speed up the TS compilation process. And if that recollection is correct, it would mean that we now have conflicting rules for the usage of the TypeScript language. What would be the best way forward? Should I close this bug and create a new issue with a feature request to enable this new awesome feature even when an explicit type annotation is present on the const? |
I can't necessarily comment on the original rationale; however, the current behavior allows users to "opt out" of using a condition for narrowing, and gives us room for some different sort of annotation in the future to signal "this is a boolean, and you should interpret the condition here". |
Perhaps something like |
Bug Report
π Search Terms
Aliased Conditions
π Version & Regression Information
V4.4.0-beta / nightly
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Adding the explicit type to "isCircle" results in that the sample breaks
π Expected behavior
Making the implicit type explicit, does not result in the behavior to change.
Using the sample provided by the TS 4.4 RC announcement, getting the implicit type of "isCircle" (by hovering over it) yields boolean
. By then explicitly defining the type (boolean), the Aliased Conditions seems to break/revert back to pre 4.4 behavior.
The text was updated successfully, but these errors were encountered: