Description
π Search Terms
mapped type array subclass numeric constraint
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
class SubArray<T> extends Array<T> {
lastPushed: undefined | T;
}
type Test<T extends ReadonlyArray<any>> = {
[K in keyof T]: T[K];
};
type Result = Test<SubArray<number>>;
// ^?
type Push = Result["push"];
// ^?
π Actual behavior
This mapped type doesn't have a homomorphic instantiation - its arrayness is not preserved. But yet all members are mapped to the Array
's type argument
π Expected behavior
I'm not entirely sure. On one hand, it feels that those members should be instantiated with the type of the original member. This wouldn't work with generic mapped types as T[K]
has the numeric constraint when T
has an array/tuple constraint. So the generic constraints wouldn't match what those could end up being instantiated with.
Should the result be a remapped subclassed array? That means that extra members wouldn't be mappable... but hey, regular array methods etc arent. So perhaps that's the most appropriate solution here.
cc @ahejlsberg
Additional information about the issue
No response