Skip to content

@switch type narrowing doesn't work #52077

Closed
@ArielGueta

Description

@ArielGueta

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

interface Base {
  type: 'foo' | 'bar'
}

interface Foo extends Base {
  type: 'foo';
  foo: string;
}

interface Bar extends Base {
  type: 'bar';
  bar: number;
}

@Component({
  selector: 'app-root',
  standalone: true,
  template: `
@switch (v.type) {
  @case ('bar') {
    {{ v.bar }}
  }

  @case ('foo') {
    {{ v.foo }}
  }

  @default {
    Default
  }
}
  `
})
export class AppComponent {
   v: Foo | Bar = { type: 'foo', foo: 'foo' };
}
Screenshot 2023-10-06 at 16 52 13

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

It should work similar to typescript code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions