If I have a template like this (readOnly
is a boolean and arrayOfStuff
is an array):
<span *ngIf="!readOnly && arrayOfStuff && arrayOfStuff.length">Hey</span>
ng build --prod
orng serve --prod
both give the error:
ERROR in /Development/project/src/$$_gendir/app/components/thing/thing.component.ngfactory.ts (767,11): Type 'number' is not assignable to type 'boolean'.
...but if I remove the boolean check it works fine:
<span *ngIf="arrayOfStuff && arrayOfStuff.length">Hey</span>
...or if I make the length check specifically a numeric comparison it works fine:
<span *ngIf="!readOnly && arrayOfStuff && (arrayOfStuff.length >0)">Hey</span>
Why is it OK to do a falsy check against arrayOfStuff.length
when I'm checking if an object exists, but it is not OK to do this when I'm checking the value of a boolean along with it?
Again, this only happens when I am actually generating a production build with ng build --prod
or ng serve --prod
. It is not a problem for development.
To be clear - I can make the problem go away, but I want to understand why it is OK to check arrayOfStuff.length
directly in one case, and not in the other.
Angular v4, @angular/cli v1.0.1.