Skip to content

Commit

Permalink
move tuple/array handling from resolveMappedTypeMembers to `forEach…
Browse files Browse the repository at this point in the history
…MappedTypePropertyKeyTypeAndIndexSignatureKeyType`
  • Loading branch information
Andarist committed Nov 11, 2023
1 parent e33988d commit b5c12ee
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13701,6 +13701,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(type: Type, include: TypeFlags, stringsOnly: boolean, cb: (keyType: Type) => void) {
if (isTupleType(type)) {
forEachType(getUnionType(getElementTypes(type).map((_, i) => getStringLiteralType("" + i))), cb);
return;
}
if (isArrayType(type)) {
cb(numberType);
return;
}
for (const prop of getPropertiesOfType(type)) {
cb(getLiteralTypeFromProperty(prop, include));
}
Expand Down Expand Up @@ -13735,15 +13743,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const include = keyofStringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique;
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
// We have a { [P in keyof T]: X }
if (isTupleType(modifiersType)) {
forEachType(getUnionType(getElementTypes(modifiersType).map((_, i) => getStringLiteralType("" + i))), addMemberForKeyType);
}
else if (isArrayType(modifiersType)) {
addMemberForKeyType(numberType);
}
else {
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
}
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
}
else {
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
Expand Down

0 comments on commit b5c12ee

Please sign in to comment.