π Search Terms
mapped tuple type, const inference
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about mapped types
β― Playground Link
https://www.typescriptlang.org/play?ssl=13&ssc=1&pln=1&pc=1#code/MYGwhgzhAEAiCmwD2ATeAnAPAFQHzQG9oBfAKFNEhmwFcAHEeBZNLZAOwgBdpaH5sATzrxo8AB5d47FDABK8MCiTsQggILp0YQZnY0AtgCMMufBKkyYzVBhz1GQkfgKlo76B27oawLknQACmkudEEbVggALkJoAG0AaWgAS3ZoAGt4QSQAM14HAWF4AF0YiLs+RyLE4vxiAEpCNw8WiHoMQPqAbmb3MjJSNEp0US8eIdt0AEYyxEm9QxN0XB6h8BHPFW5oCdYAJlmWO29UgHMV0gB6S+gASXYcjBGUaH98-nKsfWMMONqKLY8LgFT7QAC80HY8AA7u9GJ9AnFdhgpgAaHZzfbFbqkIA
π» Code
class Decoder<T> { }
class TupleDecoder<const TupleType extends ReadonlyArray<number>> extends Decoder<TupleType> {
constructor(entryDecoders: { [K in keyof TupleType]: Decoder<TupleType[K]> }) {
super();
}
}
declare const decoder1: Decoder<number>;
declare const decoder2: Decoder<string>;
// Inferred to TupleDecoder<number[]>
const tupleDecoder = new TupleDecoder([decoder1, decoder2]);
π Actual behavior
The type of tupleDecoder is inferred to TupleDecoder<number[]>
π Expected behavior
It should be inferred to be TupleDecoder<readonly [number, string]>.
Additional information about the issue
I believe this problem is probably two seperate problems.
One is that const ... extends ReadonlyArray<any> isn't being considered for mapped types.
Second is that inference is not picking up the string type in the array due to the mapped type.
π Search Terms
mapped tuple type, const inference
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ssl=13&ssc=1&pln=1&pc=1#code/MYGwhgzhAEAiCmwD2ATeAnAPAFQHzQG9oBfAKFNEhmwFcAHEeBZNLZAOwgBdpaH5sATzrxo8AB5d47FDABK8MCiTsQggILp0YQZnY0AtgCMMufBKkyYzVBhz1GQkfgKlo76B27oawLknQACmkudEEbVggALkJoAG0AaWgAS3ZoAGt4QSQAM14HAWF4AF0YiLs+RyLE4vxiAEpCNw8WiHoMQPqAbmb3MjJSNEp0US8eIdt0AEYyxEm9QxN0XB6h8BHPFW5oCdYAJlmWO29UgHMV0gB6S+gASXYcjBGUaH98-nKsfWMMONqKLY8LgFT7QAC80HY8AA7u9GJ9AnFdhgpgAaHZzfbFbqkIA
π» Code
π Actual behavior
The type of
tupleDecoderis inferred toTupleDecoder<number[]>π Expected behavior
It should be inferred to be
TupleDecoder<readonly [number, string]>.Additional information about the issue
I believe this problem is probably two seperate problems.
One is that
const ... extends ReadonlyArray<any>isn't being considered for mapped types.Second is that inference is not picking up the string type in the array due to the mapped type.