🔎 Search Terms
class parameter generic bivariant constructor typeof extends
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20231026#code/C4TwDgpgBAggRgZ2AJwIYGNirgGwgYQHsA7JZAV00OQB4BLUrY9aAXigG8BfAPinexkMwKMQgB3KAAoAsACgAkADoVqZAHMEALlEQAbhGQBtALryAlPz4MkqZhHnzQkKAElGdlgHkAZjXQkZJTA1Hys8goBjBRUyFAQAB7AEMQAJgiwiCjC2HhE0cHU9MQ+hlA2TCx8APzlHvZQOmIGyI5y6DioCBkAYoSEnBGpEB1q0HBqOijkDnJcbaPdUAAKyIQhNGBrIfFJKemZQpi5BIHTsfyH2ce4pwWxfBxDI53I0BWeEDrutva+m9tCDx5PM5PIAPTgqBeADWTnA0Bgl1W60IRgARB97OizHJIVACQA9aptfGw+EuABCyMBNGcEEIPigfSBGKxLBxEKhRJJYLxUPJcnpUHwlyRiWSaQy1Nq02gOh8qBwCFm+J5pKhABUABZ0DIIbWEcg4VJQODQRXK2bCgBaNNRu0lBxRG3pjOZ-RqUDljSglpVXIJUGJQA
💻 Code
type AbstractableConstructor<instance = {}> = abstract new (
...args: never[]
) => instance
type InstanceOf<constructor> =
constructor extends AbstractableConstructor<infer instance> ? instance : never
class Foo {
declare bar: true
}
class Proto<proto extends AbstractableConstructor = AbstractableConstructor> {
declare instance: InstanceOf<proto>
}
// Ok
type A = Proto["instance"]
// ^? {}
// Ok
type B = Proto<typeof Foo>["instance"]
// ^? Foo
// Ok
type C = A extends B ? true : false
// ^? false
// This should be false
type Z = Proto extends Proto<typeof Foo> ? true : false
// ^? true
🙁 Actual behavior
proto is treated as bivariant with no structural comparison, resulting in Z evaluating to true.
🙂 Expected behavior
proto should be treated as covariant as only its return type is used, or compared structurally, resulting in Z evaluating to false.
Additional information about the issue
No response
🔎 Search Terms
class parameter generic bivariant constructor typeof extends
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20231026#code/C4TwDgpgBAggRgZ2AJwIYGNirgGwgYQHsA7JZAV00OQB4BLUrY9aAXigG8BfAPinexkMwKMQgB3KAAoAsACgAkADoVqZAHMEALlEQAbhGQBtALryAlPz4MkqZhHnzQkKAElGdlgHkAZjXQkZJTA1Hys8goBjBRUyFAQAB7AEMQAJgiwiCjC2HhE0cHU9MQ+hlA2TCx8APzlHvZQOmIGyI5y6DioCBkAYoSEnBGpEB1q0HBqOijkDnJcbaPdUAAKyIQhNGBrIfFJKemZQpi5BIHTsfyH2ce4pwWxfBxDI53I0BWeEDrutva+m9tCDx5PM5PIAPTgqBeADWTnA0Bgl1W60IRgARB97OizHJIVACQA9aptfGw+EuABCyMBNGcEEIPigfSBGKxLBxEKhRJJYLxUPJcnpUHwlyRiWSaQy1Nq02gOh8qBwCFm+J5pKhABUABZ0DIIbWEcg4VJQODQRXK2bCgBaNNRu0lBxRG3pjOZ-RqUDljSglpVXIJUGJQA
💻 Code
🙁 Actual behavior
protois treated as bivariant with no structural comparison, resulting inZevaluating totrue.🙂 Expected behavior
protoshould be treated as covariant as only its return type is used, or compared structurally, resulting inZevaluating tofalse.Additional information about the issue
No response