Skip to content

Commit b70784e

Browse files
authored
Improve detection of type variables in instantiated object types (#53246)
1 parent 9b7f291 commit b70784e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/compiler/checker.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18705,6 +18705,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1870518705
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((type as DeferredTypeReference).target, (type as DeferredTypeReference).node, newMapper, newAliasSymbol, newAliasTypeArguments) :
1870618706
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(target as MappedType, newMapper, newAliasSymbol, newAliasTypeArguments) :
1870718707
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
18708+
// If none of the type arguments for the outer type parameters contain type variables, it follows
18709+
// that the instantiated type doesn't reference type variables.
18710+
if (result.flags & TypeFlags.ObjectFlagsType && !((result as ObjectFlagsType).objectFlags & ObjectFlags.CouldContainTypeVariablesComputed)) {
18711+
(result as ObjectFlagsType).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed |
18712+
(some(typeArguments, couldContainTypeVariables) ? ObjectFlags.CouldContainTypeVariables : 0);
18713+
}
1870818714
target.instantiations.set(id, result);
1870918715
}
1871018716
return result;
@@ -18875,7 +18881,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1887518881
}
1887618882

1887718883
function instantiateAnonymousType(type: AnonymousType, mapper: TypeMapper, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): AnonymousType {
18878-
const result = createObjectType(type.objectFlags | ObjectFlags.Instantiated, type.symbol) as AnonymousType;
18884+
const result = createObjectType(type.objectFlags & ~(ObjectFlags.CouldContainTypeVariablesComputed | ObjectFlags.CouldContainTypeVariables) | ObjectFlags.Instantiated, type.symbol) as AnonymousType;
1887918885
if (type.objectFlags & ObjectFlags.Mapped) {
1888018886
(result as MappedType).declaration = (type as MappedType).declaration;
1888118887
// C.f. instantiateSignature
@@ -23887,7 +23893,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2388723893
}
2388823894
const result = !!(type.flags & TypeFlags.Instantiable ||
2388923895
type.flags & TypeFlags.Object && !isNonGenericTopLevelType(type) && (
23890-
objectFlags & ObjectFlags.Reference && ((type as TypeReference).node || forEach(getTypeArguments(type as TypeReference), couldContainTypeVariables)) ||
23896+
objectFlags & ObjectFlags.Reference && ((type as TypeReference).node || some(getTypeArguments(type as TypeReference), couldContainTypeVariables)) ||
2389123897
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
2389223898
objectFlags & (ObjectFlags.Mapped | ObjectFlags.ReverseMapped | ObjectFlags.ObjectRestType | ObjectFlags.InstantiationExpressionType)) ||
2389323899
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && !isNonGenericTopLevelType(type) && some((type as UnionOrIntersectionType).types, couldContainTypeVariables));

0 commit comments

Comments
 (0)