因为TypeScrip类属性可以有不同类型的getter和setter since 4.3,我不知道应该由谁来正确获取属性的getter和setter类型.
=
由于类属性被视为变量,我无法正确区分给定属性是否具有getter、nor/和setter及其类型(因为Parameters<I>
和ReturnType<I>
只能在函数/方法上工作).
对预期结果的一些 idea :
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