Where can I find my Angular 2 CLI TypeScript error?

So, I just updated my Angular CLI project to the latest version.

Angular Now CLI 1.0.0 and @ angular / common 4.0.0

After compiling a previously working project (c ng build

), I got several dozen errors, for example:

C:/tools/myproject/src/$$_gendir/app/modules/wp-components/wp-components.component.ngfactory.ts (1207,11): Type 'number | true' is not assignable to type 'boolean'.
      Type 'number' is not assignable to type 'boolean'.

      

I can solve this error, but I don't know where to find it ...

I think C:/tools/myproject/src/app/modules/wp-components/wp-components.component.ts

is the original C:/tools/myproject/src/$$_gendir/app/modules/wp-components/wp-components.component.ngfactory.ts

(which is listed in the error message).

My question is:

This file has 225 lines. What is this coordinate in the error message:(1207,11)

If you have a solution to this problem, it is also welcome .; -)

Thanks guys in advance!

+3


source to share


1 answer


Had the same problem when I updated the Angular CLI.

Problem:

The source for this is logical, but I just didn't think about it.

In my case, I had a typed custom parameter or type variable as a string or number, but I used it in an if clause without a statement to check if it was empty or not.

For example:

export class ExampleType {
   id: number,
   title: string
}

if(!ExampleType.id) {
    // this will produce an error because ExampleType.id
    // is used as a boolean in this case
}

      



while using it this way will get rid of the error:

if(ExampleType.id < 1) {
    // this works
}

      

Understanding the debug message:

As far as I can see, the numbers don't make sense, but the file names seem to be the first case of one of the above cases. So if you get an error, just search that file for the if / switch conditions that might use your parameter as above and change them to use the correct comparison operator, then look at the next filename that comes after it restart. Please note, you need to check the component.ts file as well as the component.html file as it also affects the ngIfs in the template file.

Tip for detecting erroneous attributes:

The debug message does not provide any information about which attribute is the source of the errors. My solution was to just change every attribute in my custom Type to "any" and then change it one by one to see where the error started coming back again. (maybe it helps)

+3


source







All Articles