fix(ivy): types in .d.ts files should account for generics (#24862)
Ivy definition types have a generic type which specifies the return type of the factory function. For example: static ngDirectiveDef<NgForOf, '[ngFor][ngForOf]'> However, in this case NgForOf itself has a type parameter <T>. Thus, writing the above is incorrect. This commit modifies ngtsc to understand the genericness of NgForOf and to write the following: static ngDirectiveDef<NgForOf<any>, '[ngFor][ngForOf]'> PR Close #24862
This commit is contained in:

committed by
Victor Berchet

parent
2b8b647006
commit
41ef75869c
@ -143,6 +143,7 @@ export function extractDirectiveMetadata(
|
||||
inputs: {...inputsFromMeta, ...inputsFromFields},
|
||||
outputs: {...outputsFromMeta, ...outputsFromFields}, queries, selector,
|
||||
type: new WrappedNodeExpr(clazz.name !),
|
||||
typeArgumentCount: (clazz.typeParameters || []).length,
|
||||
typeSourceSpan: null !, usesInheritance,
|
||||
};
|
||||
return {decoratedElements, decorator: directive, metadata};
|
||||
|
@ -305,8 +305,14 @@ export class TypeTranslatorVisitor implements ExpressionVisitor, TypeVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
visitExpressionType(type: ExpressionType, context: Context): any {
|
||||
return type.value.visitExpression(this, context);
|
||||
visitExpressionType(type: ExpressionType, context: Context): string {
|
||||
const exprStr = type.value.visitExpression(this, context);
|
||||
if (type.typeParams !== null) {
|
||||
const typeSegments = type.typeParams.map(param => param.visitType(this, context));
|
||||
return `${exprStr}<${typeSegments.join(',')}>`;
|
||||
} else {
|
||||
return exprStr;
|
||||
}
|
||||
}
|
||||
|
||||
visitArrayType(type: ArrayType, context: Context): string {
|
||||
|
Reference in New Issue
Block a user