docs(docs-infra): extract call signature return type.

fixes #66799
This commit is contained in:
Matthieu Riegler
2026-02-03 10:50:46 +01:00
committed by Leon Senft
parent cfa7664361
commit 43d61ecbb2
2 changed files with 37 additions and 3 deletions
@@ -152,12 +152,23 @@ function extractReturnType(signature: ts.Signature, typeChecker: ts.TypeChecker)
return signature.declaration.type.getText();
}
return typeChecker.typeToString(
typeChecker.getReturnTypeOfSignature(signature),
const returnType = typeChecker.getReturnTypeOfSignature(signature);
const returnTypeString = typeChecker.typeToString(
returnType,
undefined,
// This ensures that e.g. `T | undefined` is not reduced to `T`.
ts.TypeFormatFlags.NoTypeReduction | ts.TypeFormatFlags.NoTruncation,
);
if (
returnTypeString === 'any' &&
signature.declaration?.type &&
signature.declaration.type.kind !== ts.SyntaxKind.AnyKeyword
) {
return signature.declaration.type.getText();
}
return returnTypeString;
}
/** Finds the implementation of the given function declaration overload signature. */
@@ -8,7 +8,6 @@
import {DocEntry} from '../../../src/ngtsc/docs';
import {
ClassEntry,
EntryType,
InterfaceEntry,
MemberTags,
@@ -382,5 +381,29 @@ runInEachFileSystem(() => {
expect(ageSetterEntry.type).toBe('number');
expect(ageSetterEntry.memberTags).toContain(MemberTags.Inherited);
});
it('should extract return type for call signature', () => {
env.write(
'index.ts',
`
export interface AsyncValidatorFn {
(
control: AbstractControl,
): Promise<ValidationErrors | null> | Observable<ValidationErrors | null>;
}
`,
);
const docs: DocEntry[] = env.driveDocsExtraction('index.ts');
const interfaceEntry = docs[0] as InterfaceEntry;
expect(interfaceEntry.members.length).toBe(1);
const methodEntry = interfaceEntry.members[0] as MethodEntry;
expect(methodEntry.memberType).toBe(MemberType.Method);
expect(methodEntry.name).toBe('');
expect(methodEntry.implementation.returnType).toBe(
'Promise<ValidationErrors | null> | Observable<ValidationErrors | null>',
);
});
});
});