Skip to content

feat(core): Allow other expression for exhaustive typechecking#67748

Merged
leonsenft merged 1 commit intoangular:mainfrom
JeanMeche:core/default-never-param
Mar 24, 2026
Merged

feat(core): Allow other expression for exhaustive typechecking#67748
leonsenft merged 1 commit intoangular:mainfrom
JeanMeche:core/default-never-param

Conversation

@JeanMeche
Copy link
Copy Markdown
Member

@JeanMeche JeanMeche commented Mar 19, 2026

When the switched expression is nested within a union, exhaustive typechecking needs to know which expression to check. This change adds the possibility of specifying the expression to check:

@Component({
  template: `
    @switch (state.mode) {
      @case ('show') { {{ state.menu }}; }
      @case ('hide') {}
      @default never(state);
    }
  `,
})
export class App {
  state!: { mode: 'hide' } | { mode: 'show'; menu: number };;
}

fixes #67406

@JeanMeche JeanMeche requested review from atscott and crisbeto March 19, 2026 00:49
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels Mar 19, 2026
@ngbot ngbot bot added this to the Backlog milestone Mar 19, 2026
@JeanMeche JeanMeche force-pushed the core/default-never-param branch from e5b94d3 to 30117bd Compare March 19, 2026 00:51
When the switched expression is nested within a union, exhaustive typechecking needs to know which expression to check.
This change adds the possibility of specifying the expression to check:

```
@component({
  selector: 'app-root',
  imports: [],
  template: `
    @switch (state.mode) {
      @case ('show') { {{ state.menu }}; }
      @case ('hide') {}
      @default never(state);
    }
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class App {
  state!: { mode: 'hide' } | { mode: 'show'; menu: number };;
}
```

fixes angular#67406
@JeanMeche JeanMeche added the target: major This PR is targeted for the next major release label Mar 20, 2026
@JeanMeche JeanMeche removed the request for review from crisbeto March 24, 2026 18:27
@JeanMeche JeanMeche added the action: merge The PR is ready for merge by the caretaker label Mar 24, 2026
@leonsenft leonsenft merged commit 8bc31a5 into angular:main Mar 24, 2026
23 checks passed
@leonsenft
Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@JeanMeche JeanMeche deleted the core/default-never-param branch March 24, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@switch exhaustiveness does not work for @for loop nad @if variables

3 participants