Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Oct 6, 2023

Currently we rely on native if and switch 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.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 6, 2023
@crisbeto crisbeto added this to the v17-candidates milestone Oct 6, 2023
@crisbeto crisbeto requested a review from atscott October 6, 2023 08:52
@crisbeto crisbeto marked this pull request as ready for review October 6, 2023 08:53
@crisbeto crisbeto requested a review from JoostK October 9, 2023 09:04
…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.
@crisbeto
Copy link
Member Author

Rebased and addressed the feedback.

@crisbeto crisbeto removed the request for review from JoostK October 10, 2023 08:48
@crisbeto
Copy link
Member Author

Caretaker note: please ignore the Windows failures. The failures are unrelated and the CI seems to have gotten stuck in the flaky state.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 10, 2023
@angular-robot
Copy link
Contributor

angular-robot bot commented Oct 10, 2023

This PR was merged into the repository by commit ac0d5dc.

@angular-robot angular-robot bot closed this in 16ff08e Oct 10, 2023
angular-robot bot pushed a commit that referenced this pull request Oct 10, 2023
…de switch blocks (#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 #52052.

PR Close #52069
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 11, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if block type narrowing is not applied to event bindings
2 participants