diff --git a/packages/compiler/src/metadata_resolver.ts b/packages/compiler/src/metadata_resolver.ts index ff85eb216c..2fc245af37 100644 --- a/packages/compiler/src/metadata_resolver.ts +++ b/packages/compiler/src/metadata_resolver.ts @@ -989,8 +989,6 @@ export class CompileMetadataResolver { `Can't resolve all parameters for ${stringifyType(typeOrFunc)}: (${depsTokens}).`; if (throwOnUnknownDeps || this._config.strictInjectionParameters) { this._reportError(syntaxError(message), typeOrFunc); - } else { - this._console.warn(`Warning: ${message} This will become an error in Angular v6.x`); } } diff --git a/packages/compiler/test/aot/compiler_spec.ts b/packages/compiler/test/aot/compiler_spec.ts index 3084b9d390..c960a38e0a 100644 --- a/packages/compiler/test/aot/compiler_spec.ts +++ b/packages/compiler/test/aot/compiler_spec.ts @@ -190,23 +190,64 @@ describe('compiler (unbundled Angular)', () => { }); describe('errors', () => { - it('should only warn if not all arguments of an @Injectable class can be resolved', () => { + it('should not error or warn if an unprovided @Injectable with DI-incompatible ' + + 'constructor is discovered', + () => { + const FILES: MockDirectory = { + app: { + 'app.ts': ` + import {Injectable, NgModule} from '@angular/core'; + + // This injectable is not provided. It is used as a base class for another + // service but is not directly provided. It's allowed for such classes to + // have a decorator applied as they use Angular features. + @Injectable() + export class ServiceBase { + constructor(a: boolean) {} + + ngOnDestroy() {} + } + + @Injectable() + export class MyService extends ServiceBase { + constructor() { + super(true); + } + } + + @NgModule({providers: [MyService]}) + export class AppModule {} + ` + } + }; + + spyOn(console, 'error'); + spyOn(console, 'warn'); + expect(() => compile([FILES, angularFiles])).not.toThrowError(); + expect(console.warn).toHaveBeenCalledTimes(0); + expect(console.error).toHaveBeenCalledTimes(0); + }); + + it('should error if parameters of a provided @Injectable class cannot be resolved', () => { const FILES: MockDirectory = { app: { 'app.ts': ` - import {Injectable} from '@angular/core'; + import {Injectable, NgModule} from '@angular/core'; - @Injectable() - export class MyService { - constructor(a: boolean) {} - } - ` + @Injectable() + export class MyService { + constructor(a: boolean) {} + } + + @NgModule({ + providers: [MyService], + }) + export class MyModule {} + ` } }; - 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 v6.x`); + expect(() => compile([FILES, angularFiles])) + .toThrowError(`Can't resolve all parameters for MyService in /app/app.ts: (?).`); }); it('should error if not all arguments of an @Injectable class can be resolved if strictInjectionParameters is true',