Skip to content

Commit af142b3

Browse files
committed
Address CR feedback
1 parent 2980eae commit af142b3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19770,16 +19770,20 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1977019770
// We apply the mapped type's template type to each of the fixed part elements. For variadic elements, we
1977119771
// apply the mapped type itself to the variadic element type. For other elements in the variable part of the
1977219772
// tuple, we surround the element type with an array type and apply the mapped type to that. This ensures
19773-
// that we get sequential property key types ("0", "1", "2", etc.) for the fixed part of the tuple, and
19774-
// property key type number for the remaining elements.
19773+
// that we get sequential property key types for the fixed part of the tuple, and property key type number
19774+
// for the remaining elements. For example
19775+
//
19776+
// type Keys<T> = { [K in keyof T]: K };
19777+
// type Foo<T extends any[]> = Keys<[string, string, ...T, string]>; // ["0", "1", ...Keys<T>, number]
19778+
//
1977519779
const elementFlags = tupleType.target.elementFlags;
1977619780
const fixedLength = tupleType.target.fixedLength;
1977719781
const fixedMapper = fixedLength ? prependTypeMapping(typeVariable, tupleType, mapper) : mapper;
1977819782
const newElementTypes = map(getElementTypes(tupleType), (type, i) => {
1977919783
const flags = elementFlags[i];
1978019784
return i < fixedLength ? instantiateMappedTypeTemplate(mappedType, getStringLiteralType("" + i), !!(flags & ElementFlags.Optional), fixedMapper) :
1978119785
flags & ElementFlags.Variadic ? instantiateType(mappedType, prependTypeMapping(typeVariable, type, mapper)) :
19782-
getElementTypeOfArrayType(instantiateType(mappedType, prependTypeMapping(typeVariable, createArrayType(type), mapper))) || unknownType;
19786+
getElementTypeOfArrayType(instantiateType(mappedType, prependTypeMapping(typeVariable, createArrayType(type), mapper))) ?? unknownType;
1978319787
});
1978419788
const modifiers = getMappedTypeModifiers(mappedType);
1978519789
const newElementFlags = modifiers & MappedTypeModifiers.IncludeOptional ? map(elementFlags, f => f & ElementFlags.Required ? ElementFlags.Optional : f) :

0 commit comments

Comments
 (0)