Normalize generic tuple types with Simplifiable elements (#52385)

This commit is contained in:
Mateusz Burzyński authored and GitHub committed 2023-03-20 11:10:31 -07:00
1 parent a5e6dee6b2
commit 56aa3d522b
4 files changed
+107

No files matched your search

+7
View File
@@ -20126,6 +20126,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getNormalizedType(type: Type, writing: boolean): Type {
while (true) {
const t = isFreshLiteralType(type) ? (type as FreshableType).regularType :
isGenericTupleType(type) ? getNormalizedTupleType(type, writing) :
getObjectFlags(type) & ObjectFlags.Reference ? (type as TypeReference).node ? createTypeReference((type as TypeReference).target, getTypeArguments(type as TypeReference)) : getSingleBaseForNonAugmentingSubtype(type) || type :
type.flags & TypeFlags.UnionOrIntersection ? getNormalizedUnionOrIntersectionType(type as UnionOrIntersectionType, writing) :
type.flags & TypeFlags.Substitution ? writing ? (type as SubstitutionType).baseType : getSubstitutionIntersection(type as SubstitutionType) :
@@ -20150,6 +20151,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return type;
}
function getNormalizedTupleType(type: TupleTypeReference, writing: boolean): Type {
const elements = getTypeArguments(type);
const normalizedElements = sameMap(elements, t => t.flags & TypeFlags.Simplifiable ? getSimplifiedType(t, writing) : t);
return elements !== normalizedElements ? createNormalizedTupleType(type.target, normalizedElements) : type;
}
/**
* Checks if 'source' is related to 'target' (e.g.: is a assignable to).
* @param source The left-hand-side of the relation.