mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
committed by
Leon Senft
parent
cfa7664361
commit
43d61ecbb2
@@ -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>',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user