Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: "Expected the operants to be of similar type or any" linting error

I have a shared service file which defines a variable liks this:

export class SharedService {
    activeModal: String;
}

Then I have a component file that imports the service and defines it:

constructor(public sharedService: SharedService) {
}

In that component's template file I check the value of the modal:

<div *ngIf="sharedService.activeModal === 'login'"></div>

Everything works fine, but in the editor, the sharedService.activeModal === 'login' part get's a red squiggly line under it and hover over it shows this linting error:

[Angular] Expected the operants to be of similar type or any
property sharedService of ModalComponent

Any ideas what I'm doing wrong?

like image 817
yodalr Avatar asked Aug 07 '18 22:08

yodalr


1 Answers

Try lowercase string (the primitive, rather than the wrapper object type String) in the declaration of activeModal.

like image 167
Matt McCutchen Avatar answered Oct 21 '22 07:10

Matt McCutchen