feat(compiler): enabled strict checking of parameters to an @Injectable (#19412)

Added the compiler options `strictInjectionParameters` that defaults
to `false`. If enabled the compiler will report errors for parameters
of an `@Injectable` that cannot be determined instead of generating a
warning.

This is planned to be switched to default to `true` for Angular 6.0.
This commit is contained in:
Chuck Jazdzewski
2017-09-26 13:40:47 -07:00
committed by Victor Berchet
parent a75040d0a1
commit dfb8d21ef4
6 changed files with 37 additions and 5 deletions

View File

@ -205,10 +205,30 @@ describe('compiler (unbundled Angular)', () => {
const warnSpy = spyOn(console, 'warn');
compile([FILES, angularFiles]);
expect(warnSpy).toHaveBeenCalledWith(
`Warning: Can't resolve all parameters for MyService in /app/app.ts: (?). This will become an error in Angular v5.x`);
`Warning: Can't resolve all parameters for MyService in /app/app.ts: (?). This will become an error in Angular v6.x`);
});
it('should error if not all arguments of an @Injectable class can be resolved if strictInjectionParamters is true',
() => {
const FILES: MockDirectory = {
app: {
'app.ts': `
import {Injectable} from '@angular/core';
@Injectable()
export class MyService {
constructor(a: boolean) {}
}
`
}
};
const warnSpy = spyOn(console, 'warn');
expect(() => compile([FILES, angularFiles], {strictInjectionParameters: true}))
.toThrowError(`Can't resolve all parameters for MyService in /app/app.ts: (?).`);
expect(warnSpy).not.toHaveBeenCalled();
});
it('should be able to suppress a null access', () => {
const FILES: MockDirectory = {
app: {