angular: Incorrect template errors with union types

I’m submitting a…

[x] Bug report  

Current behavior

Imported from

With the following component

  selector: 'my-app',
  template: `
      <h2>Hello {{name}}</h2>
      <p *ngIf="name == 'steve'">hi steve</p>
export class App {
  name: string | number;
  constructor() { = `Angular!`

An error is given for the *ngIf value: [Angular] Expected the operants to be of similar type or any.

Expected behavior

No template error appears similar to

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 37
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Error happens with plain string values as well.

mystring: string;

[disabled]="mysting !== 'somestring'"

Error: property mystring of MyComponent Expected the operants to be of similar type or any

This was fixed in #36529 and also won’t be an issue anymore with the Ivy language service.

I no longer see the issue with the latest language-service plugin on VSCode and after upgrading to angular 8.1.0