Extend isTupleLikeType to also check if .length is a number literal type (#52617)

This commit is contained in:
Mateusz Burzyński
2023-06-30 04:13:02 +02:00
committed by GitHub
parent 34f6e107a3
commit 3073b5209b
6 changed files with 92 additions and 4 deletions

View File

@@ -23303,7 +23303,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function isTupleLikeType(type: Type): boolean {
return isTupleType(type) || !!getPropertyOfType(type, "0" as __String);
let lengthType;
return isTupleType(type) ||
!!getPropertyOfType(type, "0" as __String) ||
isArrayLikeType(type) && !!(lengthType = getTypeOfPropertyOfType(type, "length" as __String)) && everyType(lengthType, t => !!(t.flags & TypeFlags.NumberLiteral));
}
function isArrayOrTupleLikeType(type: Type): boolean {