question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect template errors with union types

See original GitHub issue

I’m submitting a…


[x] Bug report  

Current behavior

Imported from https://github.com/angular/vscode-ng-language-service/issues/231

With the following component

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>Hello {{name}}</h2>
      <p *ngIf="name == 'steve'">hi steve</p>
    </div>
  `,
})
export class App {
  name: string | number;
  constructor() {
    this.name = `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 https://github.com/angular/vscode-ng-language-service/issues/16

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
joshuwhicommented, Jun 4, 2019

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

1reaction
JoostKcommented, May 13, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Template Check Error while using Union Type of ...
When I display a review sometimes I just want userId as a string or sometimes I populate the userId with some user's schema...
Read more >
*ngSwitch Type Errors with Discriminated Unions in Angular ...
Here's a workaround for resolving *ngSwitch type errors in Angular templates and switching on a discriminated union type.
Read more >
Handbook - Unions and Intersection Types - TypeScript
Union Types. Occasionally, you'll run into a library that expects a parameter to be either a number or a string . For instance,...
Read more >
Invalid template errors - Azure Resource Manager
Solution 2: Incorrect segment lengths ... Another invalid template error occurs when the resource name isn't in the correct format. To resolve ...
Read more >
Using TypeScript Union Types Like a Pro | by Bytefer
Union Type in TypeScript, TypeScript Union Types, ... want the logError function to support multiple error messages in the form of an array?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found