# Bug Report ### ๐ Search Terms Mapped array types ### ๐ Version & Regression Information I noticed now in TS 4.1.2. ### โฏ Code and Playground Links There are two problems. The following has an error in the mapped type despite that I did it just like in https://github.com/microsoft/TypeScript/pull/26063 (as far as I know): ```ts type Constructor<T = object, A extends any[] = any[], Static = {}> = (new (...a: A) => T) & Static type ElementTypeArrayToInstArray<T extends Constructor[]> = { [K in keyof T]: InstanceType<T[K]> // <----------- ERROR } type ArrayValues<T extends any[]> = T[keyof T] type ElementTypes<T extends Constructor[]> = ArrayValues<ElementTypeArrayToInstArray<T>> type test = ElementTypes<[typeof HTMLAnchorElement, typeof HTMLDivElement]> ``` [Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAqUAvFHAEYBWE2ANFAIJQQAewECAJklAIYIgA2gF0SfASPoBlYL2ABLTGIDeAXwB8YgBQIIAdyhaAdCd4AuRgEoSmgtYBkUGXMUAoV6EhQAogBsIALYcwATgEAyoqLwgBHAAksjAEVEghMxsHNywiCgY2LgimqTKrgCQggDSUPIIUADWECBwAGZQBMIWCSj8mBChkISVwpoA9CNQeAC00zOzkz4ASgsA8guuqh5hjJHRAGq8vugQSGms7Fw8-ELDYgSCDU2t7ZtefoHB-cenGRfZiXk4VCFMTJPYHI4nN5BBAhMKgmLxRLwwjqdTuTzQdgoMRQj5hE6CDEtKAACQIAFkADIMBCYAAWuFxMPoRNaZKpABF5AA3JnAYauIA) But notice that when you hover on `test`, it is a union of all the values of the array including values from non-numeric keys, which is unlike the examples in #26063. There seems to some sort of special casing happening. I had to specify that I want `number` keys only in order(unlike #26063) to get rid of the error: ```js type Constructor<T = object, A extends any[] = any[], Static = {}> = (new (...a: A) => T) & Static type ElementTypeArrayToInstArray<T extends Constructor[]> = { [K in keyof T]: InstanceType<T[number & K]> // <----------- GOOD } type ArrayValues<T extends any[]> = T[keyof T] type ElementTypes<T extends Constructor[]> = ArrayValues<ElementTypeArrayToInstArray<T>> type test = ElementTypes<[typeof HTMLAnchorElement, typeof HTMLDivElement]> ``` [Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAqUAvFHAEYBWE2ANFAIJQQAewECAJklAIYIgA2gF0SfASPoBlYL2ABLTGIDeAXwB8YgBQIIAdyhaAdCd4AuRgEoSmgtYBkUGXMUAoV6EhQAogBsIALYcwATgEAyoqLwgBHAAksjAEVEghMxsHNywiCgY2LgimqTKrgCQggDSUPIIUADWECBwAGZQBMIWCSj8mBChkISCCOgB5BCoUI4VwpoA9LNQeAC0K6trS1AA4gDy2wAirqoeYYyR0QBqvL7oEEhprOxcPPxCM2IEgg1Nre3HXn6BYL9W73DJPbKJPI4VCFMTJC5XG53AFBBAhMLwmLxRKYwjqdTuTzQdgoMQooFhO6CIktKAACQIAFkADIMBCYAAWuHJaPoNNaDJZe3kADcecAZq4gA) But notice that `test` still contains all the values of all keys, not just array values. Finally, I had to specify numeric keys for `ArrayValues`: ```ts type Constructor<T = object, A extends any[] = any[], Static = {}> = (new (...a: A) => T) & Static type ElementTypeArrayToInstArray<T extends Constructor[]> = { [K in keyof T]: InstanceType<T[number & K]> } type ArrayValues<T extends any[]> = T[number & keyof T] // <-------- number type ElementTypes<T extends Constructor[]> = ArrayValues<ElementTypeArrayToInstArray<T>> type test = ElementTypes<[typeof HTMLAnchorElement, typeof HTMLDivElement]> ``` [Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAqUAvFHAEYBWE2ANFAIJQQAewECAJklAIYIgA2gF0SfASPoBlYL2ABLTGIDeAXwB8YgBQIIAdyhaAdCd4AuRgEoSmgtYBkUGXMUAoV6EhQAogBsIALYcwATgEAyoqLwgBHAAksjAEVEghMxsHNywiCgY2LgimqTKrgCQggDSUPIIUADWECBwAGZQBMIWCSj8mBChkISCCOgB5BCoUI4Vwuquqh5hjJHRAGq8vugQSGms7Fw8-EIzYgRDI2MTjg1Nre1QAPT3UHgAtG-vb1DDo+MLXn6BYL9LY7DL7bKJPI4VCFMTJVbrTbbAFBBAhMLwmLxRKYwjqWZ-aDsFBiFFAsLbQSeCAtKAACQIAFkADIMBCYAAWuDJaPo1NpDJZABF5AA3HnAGauIA) But notice if I use `Promise` instead of `InstanceType`, the first issues goes away, although `number` is still needed in `ArrayValues`: ```ts type Constructor<T = object, A extends any[] = any[], Static = {}> = (new (...a: A) => T) & Static type ElementTypeArrayToInstArray<T extends Constructor[]> = { [K in keyof T]: Promise<T[K]> // <-------- no number } type ArrayValues<T extends any[]> = T[number & keyof T] // <-------- number still needed type ElementTypes<T extends Constructor[]> = ArrayValues<ElementTypeArrayToInstArray<T>> type test = ElementTypes<[typeof HTMLAnchorElement, typeof HTMLDivElement]> ``` [Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAqUAvFHAEYBWE2ANFAIJQQAewECAJklAIYIgA2gF0SfASPoBlYL2ABLTGIDeAXwB8YgBQIIAdyhaAdCd4AuRgEoSmgtYBkUGXMUAoV6EhQAogBsIALYcwATgEAyoqLwgBHAAksjAEVEghMxsHNywiCgY2LgimqTKrgCQggDSUPIIUADWECBwAGZQBMIWAAqocAHySBCElcKaAPSjUHgAtDOzM1AIcAvoAeQQqK6qHmGMkdEAary+6BBIaazsXDz8QiNiBIIIK2uoUI4NTa3tUOOTc3PLVbrKAoeS+XwLCAQTjQ7ZePyBYKhSBnIgXTI8eCJPI4VCFMTJA5HE5nBFBBAhMKEmLxRLUwjqdTuTzQdgoMRkpFhM6CFktKAACQIAFkADIMBCYAAWuE5FPofNaQrFABF5AA3OXAEauIA) ### ๐ Actual behavior Does not work like #26063 ### ๐ Expected behavior Works like #26063 --- There seems to be some sort of special casing going on.