After upgrading from Angular 2 to Angular 4, Jasmine started to complain about values that did not even exist in my unit tests
I recently posted an article about a Jasmine issue that arose with regards to the globals: describe, beforeEach, expect and it. That turned out to be related to how types are handled in Angular 4.
Once I got that problem straightened out, there were some really odd errors. The thing that was driving me nuts was: the values that Jasmine complained about did not even exist in my unit tests… gggrrrrr.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'url' implicitly has an 'any' type. ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'backend' implicitly has an 'any' type. ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'defaultOptions' implicitly has an 'any' type. ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'mockBackend' implicitly has an 'any' type. ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'connection' implicitly has an 'any' type. ERROR in [at-loader] ./path-to/example-service.spec.ts TS7006: Parameter 'data' implicitly has an 'any' type. |
This is one that could have taken forever. Actually, I did spend at least 30 minutes scratching my head. Fortunately, I found the answer on Github: I needed to make a change to tsconfig.json. In the compilerOptions object, set noImplicitAny to false.
For example:
1 2 3 4 5 |
{ "compilerOptions": { "noImplicitAny": false } } |
Credit goes to Zama Khan Mohammed for this answer.