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 #26063 (as far as I know):
typeConstructor<T=object,Aextendsany[]=any[],Static={}>=(new(...a: A)=>T)&StatictypeElementTypeArrayToInstArray<TextendsConstructor[]>={[KinkeyofT]: InstanceType<T[K]>// <----------- ERROR}typeArrayValues<Textendsany[]>=T[keyofT]typeElementTypes<TextendsConstructor[]>=ArrayValues<ElementTypeArrayToInstArray<T>>typetest=ElementTypes<[typeofHTMLAnchorElement,typeofHTMLDivElement]>Playground link with relevant code
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:
typeConstructor<T=object,Aextendsany[]=any[],Static={}>=(new(...a: A)=>T)&StatictypeElementTypeArrayToInstArray<TextendsConstructor[]>={[KinkeyofT]: InstanceType<T[number&K]>// <----------- GOOD}typeArrayValues<Textendsany[]>=T[keyofT]typeElementTypes<TextendsConstructor[]>=ArrayValues<ElementTypeArrayToInstArray<T>>typetest=ElementTypes<[typeofHTMLAnchorElement,typeofHTMLDivElement]>Playground link with relevant code
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:
typeConstructor<T=object,Aextendsany[]=any[],Static={}>=(new(...a: A)=>T)&StatictypeElementTypeArrayToInstArray<TextendsConstructor[]>={[KinkeyofT]: InstanceType<T[number&K]>}typeArrayValues<Textendsany[]>=T[number&keyofT]// <-------- numbertypeElementTypes<TextendsConstructor[]>=ArrayValues<ElementTypeArrayToInstArray<T>>typetest=ElementTypes<[typeofHTMLAnchorElement,typeofHTMLDivElement]>Playground link with relevant code
But notice if I use Promise instead of InstanceType, the first issues goes away, although number is still needed in ArrayValues:
typeConstructor<T=object,Aextendsany[]=any[],Static={}>=(new(...a: A)=>T)&StatictypeElementTypeArrayToInstArray<TextendsConstructor[]>={[KinkeyofT]: Promise<T[K]>// <-------- no number}typeArrayValues<Textendsany[]>=T[number&keyofT]// <-------- number still neededtypeElementTypes<TextendsConstructor[]>=ArrayValues<ElementTypeArrayToInstArray<T>>typetest=ElementTypes<[typeofHTMLAnchorElement,typeofHTMLDivElement]>Playground link with relevant code
🙁 Actual behavior
Does not work like #26063
🙂 Expected behavior
Works like #26063
There seems to be some sort of special casing going on.
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 #26063 (as far as I know):
Playground link with relevant code
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
numberkeys only in order(unlike #26063) to get rid of the error:Playground link with relevant code
But notice that
teststill contains all the values of all keys, not just array values.Finally, I had to specify numeric keys for
ArrayValues:Playground link with relevant code
But notice if I use
Promiseinstead ofInstanceType, the first issues goes away, althoughnumberis still needed inArrayValues:Playground link with relevant code
🙁 Actual behavior
Does not work like #26063
🙂 Expected behavior
Works like #26063
There seems to be some sort of special casing going on.