mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 22:00:59 -05:00
Consider enclosing declaration when serializing inferred return types (#59170)
This commit is contained in:
@@ -8322,11 +8322,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const typePredicate = getTypePredicateOfSignature(signature);
|
||||
const type = getReturnTypeOfSignature(signature);
|
||||
if (context.enclosingDeclaration && (!isErrorType(type) || (context.flags & NodeBuilderFlags.AllowUnresolvedNames)) && signature.declaration && !nodeIsSynthesized(signature.declaration)) {
|
||||
const annotation = signature.declaration && getNonlocalEffectiveReturnTypeAnnotationNode(signature.declaration);
|
||||
// Default constructor signatures inherited from base classes return the derived class but have the base class declaration
|
||||
// To ensure we don't serialize the wrong type we check that that return type of the signature corresponds to the declaration return type signature
|
||||
if (annotation && getTypeFromTypeNode(context, annotation) === type) {
|
||||
const result = tryReuseExistingTypeNodeHelper(context, annotation);
|
||||
const annotation = getNonlocalEffectiveReturnTypeAnnotationNode(signature.declaration);
|
||||
if (annotation) {
|
||||
const result = tryReuseExistingTypeNode(context, annotation, type, context.enclosingDeclaration);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user