New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
array in conditional type issue #57901
Comments
This is a design limitation. Resolving of conditional types involving unbound generic types is deferred. The compiler does not know what type |
Thanks! |
It'd be wrong to produce class Item {
name!: string
}
class SuperItem extends Item {
isSuper!: true;
}
abstract class ItemContainer {
items!: Item[]
}
class SuperItemContainer extends ItemContainer {
items!: SuperItem[];
}
class Drawer extends ItemContainer {
size!: number
}
type ArrayInnerType<A> = A extends (infer inferred)[] ? inferred : A;
class Manager<T extends ItemContainer> {
manage(object: T): ArrayInnerType<T["items"]> {
// Alleged: Should be just 'Item'
type wrongType = ArrayInnerType<T["items"]>;
// Then this is OK
const p: wrongType = new Item();
return p;
}
}
const p = new Manager<SuperItemContainer>();
// x: SuperItem, but it's actually an Item
const x = p.manage(new SuperItemContainer()); |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
array in conditional type issue inheritance accessor function
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAECSAuBTAtgbwFDS9AdmZiAhAFwTwBOAljgOboC+6YARmeWMPNKJDAigGEA9jnhhqichmzRKSZBBJx5AbQC6DdOh5RoAEXYB3SdEQAPJDgAmfecNHick6dgiUAXkWI4ArsmaSmlpa8ACeAA6I0ACC5OyhsDhO5AAqEYgAPDEAfNAAvFjRphaI1jAAFNQAZibVkuSIVgCU6gD8dXGNxNEA3MHa4LoAsmB4NJIZKcWWNsqCImIS5NkuWMijYOPlQswAVoicxClNqzLQYZHQVDQAFvBplwWx8YnJD5n8yPaLySoARHIUBA-mpsn0ztgAPSQiEAPVamAh53S0EM5BENHe+WeYASSUk70m-0BChBYMREOh2HhFOgjHoQA
π» Code
π Actual behavior
actual type of wrongType is
(inferred & inferred[]) | T["items"]
π Expected behavior
wrongType is Item
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: