使用点表示法的深层方法属性的访问类型

这是具有深层方法S的类的示例。

class Core {
    read = () => true
}

class Customer extends Core {}
class Plan extends Core {}

class S {
    stripeCustomer = new Customer()
    stripePlan = new Plan()

}

type a = ReturnType<Core['read']> // boolean
type b = ReturnType<S['stripeCustomer']['read']> // boolean

这是我正在寻找的语法:

DeepMethodReturnType<A,B>

type c = DeepMethodReturnType<S,'stripeCustomer.read'>

是否可以使用点表示法访问类的深层方法?像stripeCustomer.read一样?

sgdtiancai 回答:使用点表示法的深层方法属性的访问类型

不幸的是没有使用点符号。字符串文字不能在类型级别上连接或拆分,因此这是不可能的。

I.E此方法将依赖于拆分字符串文字stripeCustomer.read 分别设置为stripeCustomerread

不过,您可以使用元组[“ stripeCustomer”,“ read”]来实现类似的语法

本文链接:https://www.f2er.com/3130507.html

大家都在问