Skip to content

feat(compiler): Support "in" operator in Angular templates #38560

@manueledones

Description

@manueledones

🚀 feature request

Description

I'd like to have your opinions about supporting "in" operator in html templates. Let's say I have an object of a union type A | B. I'd like to use the 'in' operator to differentiate type.
Something like:

export interface A {
  a: number
}

export interface B {
  b: string
}

export type MyUnionType = A | B;

item: MyUnionType = {
    a: 1
  }

<div *ngIf="'a' in item">
  I'm expecting item is no longer of type A | B, but only A
  {{item.a}}
</div>

Here is a stackblitz

Metadata

Metadata

Assignees

Labels

area: compilerIssues related to `ngc`, Angular's template compilerarea: coreIssues related to the framework runtimecore: binding & interpolationIssue related to property/attribute binding or text interpolationfeatureIssue that requests a new feature

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions