Since TypeScript 4.3 introduced the ability for class properties to have getters and setters of different types since 4.3, I am unsure how to correctly retrieve the types of a property's getter and setter.
===
Since a class property is treated as a variable, it is challenging to determine if the property has a getter, a setter, or both, and their respective types (as Parameters<I>
and ReturnType<I>
are only applicable to functions/methods).
Here are some expected results:
class Foo {
get bar(): number { /** ... */ }
set bar(baz: string) { /** ... */ }
}
type GetterOfFooBar = GetterOf<typeof Foo.prototype.bar>; // number
type SetterOfFooBar = SetterOf<typeof Foo.prototype.bar>; // string
class Foo {
get bar(): number { /** ... */ }
}
type GetterOfFooBar = GetterOf<typeof Foo.prototype.bar>; // number
type SetterOfFooBar = SetterOf<typeof Foo.prototype.bar>; // never