Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Type narrowing for `NgSwitch` and `NgSwitchCase` #20780
Comments
|
Looking forward to see type guard support in language-service as well! My simple use case: interface Animal {
type: 'fish' | 'bird';
}
interface Fish extends Animal {
type: 'fish';
foo: string;
}
interface Bird extends Animal {
type: 'bird';
bar: string;
}
@Component({})
class MyComponent {
animal: Animal;
isFish(animal: Animal): animal is Fish {
return animal.type === 'fish';
}
isBird(animal: Animal): animal is Bird {
return animal.type === 'bird';
}
}Use case 1 <app-fish *ngIf="isFish(animal)" [foo]="animal.foo"></app-fish>
<app-bird *ngIf="isBird(animal)" [bar]="animal.bar"></app-bird>Use case 2 <ng-container [ngSwitch]="true">
<app-fish *ngSwitchCase="isFish(animal)"></app-fish>
<app-bird *ngSwitchCase="isBird(animal)"></app-bird>
</ng-container>Are both use cases covered? |
|
This would be a great addition, having an issue similar to case 2 that @dirkluijk posted. |
|
@chuckjaz any updates? Anyone working on this? Thanks |
|
Will this be solved in Ivy? |
|
No, this isn't solved by Ivy, if anything, Ivy will cause more people to realize how badly they need |
|
This would really clean up a lot of template code. How come this is such a low priority? |
Current behavior
No type narrowing is performed when using
NgSwitchandNgSwitchCase.Expected behavior
Narrow the types used in the
NgSwitchCasebased on the selection criteria.See #17953 (comment) and following for more details.