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

fix(compiler): work around TypeScript bug when narrowing switch statements #52110

Closed
wants to merge 1 commit into from

Commits on Oct 9, 2023

  1. fix(compiler): work around TypeScript bug when narrowing switch state…

    …ments
    
    We type check `@switch` blocks by generating identical TS `switch` statements in the TCB, however TS currently has a bug where parenthesized `switch` block expressions don't narrow their types. Since we use parenthesized expressions to wrap AST nodes for diagnostics, this will bug will affect all Angular-generated `switch` statements.
    
    These changes work around the issue by generating `if`/`else if`/`else` statements that represent the `switch`.
    
    Some alternatives that were considered:
    1. Moving the `switch` expression to a constant - this is fairly simple to implement, but it won't fully resolve the narrowing issue since the same constant will have to be used in expressions inside the different cases.
    2. Removing the outer-most parenthesis from the switch expression - this works and allows us to continue using switch statements, but because we use parenthesized expressions to map diagnostics to their template locations, I wasn't sure if it won't lead to worse template dignostics.
    
    Fixes angular#52077.
    crisbeto committed Oct 9, 2023
    Copy the full SHA
    e47f387 View commit details
    Browse the repository at this point in the history