Closed as not planned
Description
π 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
π» 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.