mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Normalize generic tuple types with Simplifiable elements (#52385)
This commit is contained in:
1 parent
a5e6dee6b2
commit
56aa3d522b
4 files changed
+107
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user