fix(compiler): support interface types in injectable constuctors (#14894)
Fixes #12631
This commit is contained in:
@ -726,6 +726,31 @@ describe('StaticReflector', () => {
|
||||
expect(reflector.annotations(reflector.getStaticSymbol('/tmp/src/main.ts', 'Child')))
|
||||
.toEqual([]);
|
||||
});
|
||||
|
||||
it('should support constructor parameters with @Inject and an interface type', () => {
|
||||
const data = Object.create(DEFAULT_TEST_DATA);
|
||||
const file = '/tmp/src/inject_interface.ts';
|
||||
data[file] = `
|
||||
import {Injectable, Inject} from '@angular/core';
|
||||
import {F} from './f';
|
||||
|
||||
export interface InjectedInterface {
|
||||
|
||||
}
|
||||
|
||||
export class Token {}
|
||||
|
||||
@Injectable()
|
||||
export class SomeClass {
|
||||
constructor (@Inject(Token) injected: InjectedInterface, t: Token, @Inject(Token) f: F) {}
|
||||
}
|
||||
`;
|
||||
|
||||
init(data);
|
||||
|
||||
expect(reflector.parameters(reflector.getStaticSymbol(file, 'SomeClass'))[0].length)
|
||||
.toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -424,7 +424,9 @@ export class MockStaticSymbolResolverHost implements StaticSymbolResolverHost {
|
||||
filePath, this.data[filePath], ts.ScriptTarget.ES5, /* setParentNodes */ true);
|
||||
const diagnostics: ts.Diagnostic[] = (<any>sf).parseDiagnostics;
|
||||
if (diagnostics && diagnostics.length) {
|
||||
throw Error(`Error encountered during parse of file ${filePath}`);
|
||||
const errors = diagnostics.map(d => `(${d.start}-${d.start+d.length}): ${d.messageText}`)
|
||||
.join('\n ');
|
||||
throw Error(`Error encountered during parse of file ${filePath}\n${errors}`);
|
||||
}
|
||||
return [this.collector.getMetadata(sf)];
|
||||
}
|
||||
|
Reference in New Issue
Block a user