@@ -19770,16 +19770,20 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
19770
19770
// We apply the mapped type's template type to each of the fixed part elements. For variadic elements, we
19771
19771
// apply the mapped type itself to the variadic element type. For other elements in the variable part of the
19772
19772
// 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
+ //
19775
19779
const elementFlags = tupleType.target.elementFlags;
19776
19780
const fixedLength = tupleType.target.fixedLength;
19777
19781
const fixedMapper = fixedLength ? prependTypeMapping(typeVariable, tupleType, mapper) : mapper;
19778
19782
const newElementTypes = map(getElementTypes(tupleType), (type, i) => {
19779
19783
const flags = elementFlags[i];
19780
19784
return i < fixedLength ? instantiateMappedTypeTemplate(mappedType, getStringLiteralType("" + i), !!(flags & ElementFlags.Optional), fixedMapper) :
19781
19785
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;
19783
19787
});
19784
19788
const modifiers = getMappedTypeModifiers(mappedType);
19785
19789
const newElementFlags = modifiers & MappedTypeModifiers.IncludeOptional ? map(elementFlags, f => f & ElementFlags.Required ? ElementFlags.Optional : f) :
0 commit comments