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
Narrow types in event listeners inside conditional blocks #52069
Conversation
7cc0c55
to
97b8b05
Compare
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
…de if blocks Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback. Fixes angular#52052.
…de switch blocks Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback. Fixes angular#52052.
97b8b05
to
f339366
Compare
Rebased and addressed the feedback. |
Caretaker note: please ignore the Windows failures. The failures are unrelated and the CI seems to have gotten stuck in the flaky state. |
This PR was merged into the repository by commit ac0d5dc. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…de if blocks (angular#52069) Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback. Fixes angular#52052. PR Close angular#52069
…de switch blocks (angular#52069) Since expressions in event listener are added inside of a callback, type narrowing won't apply to them anymore. These changes add the logic to create a guard expression that will re-narrow the expression in the callback. Fixes angular#52052. PR Close angular#52069
Currently we rely on native
if
andswitch
blocks to do the type narrowing for us in the new control flow syntax. This works for most cases, except for event listeners. Since event listener expressions are inside callback functions, type narrowing doesn't apply to them anymore. These changes work around it by reconstructing an expression to re-narrow the type in such cases.Fixes #52052.