Microsoft/TypeScript
Ver no GitHubClass parameter incorrectly treated as bivariant
Open
#56.225 aberto em 26 de out. de 2023
BugDomain: check: Variance RelationshipsHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 Search Terms
class parameter generic bivariant constructor typeof extends
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 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