fix(ivy): ngtsc should include generic types on injectable definitions (#27037)

Analogously to directives, the `ngInjectableDef` field in .d.ts files is
annotated with the type of service that it represents. If the service
contains required generic type arguments, these must be included in
the .d.ts file.

PR Close #27037
This commit is contained in:
JoostK
2018-11-10 02:58:33 +01:00
committed by Igor Minar
parent 7f221d8d2a
commit 159ab1c257
7 changed files with 34 additions and 12 deletions

View File

@ -78,6 +78,7 @@ export interface R3PipeMetadataFacade {
export interface R3InjectableMetadataFacade {
name: string;
type: any;
typeArgumentCount: number;
ctorDeps: R3DependencyMetadataFacade[]|null;
providedIn: any;
useClass?: any;

View File

@ -10,7 +10,7 @@ import {InjectFlags} from './core';
import {Identifiers} from './identifiers';
import * as o from './output/output_ast';
import {R3DependencyMetadata, R3FactoryDelegateType, R3FactoryMetadata, compileFactoryFunction} from './render3/r3_factory';
import {mapToMapExpression} from './render3/util';
import {mapToMapExpression, typeWithParameters} from './render3/util';
export interface InjectableDef {
expression: o.Expression;
@ -21,6 +21,7 @@ export interface InjectableDef {
export interface R3InjectableMetadata {
name: string;
type: o.Expression;
typeArgumentCount: number;
ctorDeps: R3DependencyMetadata[]|null;
providedIn: o.Expression;
useClass?: o.Expression;
@ -33,10 +34,6 @@ export interface R3InjectableMetadata {
export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
let result: {factory: o.Expression, statements: o.Statement[]}|null = null;
function makeFn(ret: o.Expression): o.Expression {
return o.fn([], [new o.ReturnStatement(ret)], undefined, undefined, `${meta.name}_Factory`);
}
const factoryMeta = {
name: meta.name,
type: meta.type,
@ -100,8 +97,8 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
const expression = o.importExpr(Identifiers.defineInjectable).callFn([mapToMapExpression(
{token, factory: result.factory, providedIn})]);
const type = new o.ExpressionType(
o.importExpr(Identifiers.InjectableDef, [new o.ExpressionType(meta.type)]));
const type = new o.ExpressionType(o.importExpr(
Identifiers.InjectableDef, [typeWithParameters(meta.type, meta.typeArgumentCount)]));
return {
expression,

View File

@ -45,6 +45,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
const {expression, statements} = compileInjectable({
name: facade.name,
type: new WrappedNodeExpr(facade.type),
typeArgumentCount: facade.typeArgumentCount,
providedIn: computeProvidedIn(facade.providedIn),
useClass: wrapExpression(facade, USE_CLASS),
useFactory: wrapExpression(facade, USE_FACTORY),