Skip to content

Commit 16bc58f

Browse files
committed
Propagate base type mapper in signatures with inferred type parameters
1 parent 994f390 commit 16bc58f

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/compiler/checker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16316,8 +16316,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1631616316
if (returnSignature) {
1631716317
const newReturnSignature = cloneSignature(returnSignature);
1631816318
newReturnSignature.typeParameters = inferredTypeParameters;
16319+
const newReturnType = getOrCreateTypeFromSignature(newReturnSignature) as AnonymousType;
16320+
newReturnType.mapper = instantiatedSignature.mapper;
1631916321
const newInstantiatedSignature = cloneSignature(instantiatedSignature);
16320-
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
16322+
newInstantiatedSignature.resolvedReturnType = newReturnType;
1632116323
return newInstantiatedSignature;
1632216324
}
1632316325
}
@@ -16409,7 +16411,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1640916411
// If declaration is undefined, it is likely to be the signature of the default constructor.
1641016412
const isConstructor = kind === undefined || kind === SyntaxKind.Constructor || kind === SyntaxKind.ConstructSignature || kind === SyntaxKind.ConstructorType;
1641116413

16412-
const type = createObjectType(ObjectFlags.Anonymous);
16414+
const type = createObjectType(ObjectFlags.Anonymous | ObjectFlags.SingleSignatureType, signature.declaration?.symbol);
1641316415
type.members = emptySymbols;
1641416416
type.properties = emptyArray;
1641516417
type.callSignatures = !isConstructor ? [signature] : emptyArray;
@@ -20528,7 +20530,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2052820530
}
2052920531
let result = target.instantiations.get(id);
2053020532
if (!result) {
20531-
const newMapper = createTypeMapper(typeParameters, typeArguments);
20533+
let newMapper = createTypeMapper(typeParameters, typeArguments);
20534+
if (target.objectFlags & ObjectFlags.SingleSignatureType && mapper) {
20535+
newMapper = combineTypeMappers(newMapper, mapper);
20536+
}
2053220537
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((type as DeferredTypeReference).target, (type as DeferredTypeReference).node, newMapper, newAliasSymbol, newAliasTypeArguments) :
2053320538
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(target as MappedType, newMapper, newAliasSymbol, newAliasTypeArguments) :
2053420539
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6492,7 +6492,7 @@ export const enum ObjectFlags {
64926492
CouldContainTypeVariablesComputed = 1 << 19, // CouldContainTypeVariables flag has been computed
64936493
/** @internal */
64946494
CouldContainTypeVariables = 1 << 20, // Type could contain a type variable
6495-
6495+
SingleSignatureType = 1 << 27,
64966496
ClassOrInterface = Class | Interface,
64976497
/** @internal */
64986498
RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral,

0 commit comments

Comments
 (0)