[英]Access type for deep method property using dot notation
Here's an example of a class with deep methods S
.这是一个带有深度方法
S
的 class 示例。
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
This is the syntax I am looking for:这是我正在寻找的语法:
DeepMethodReturnType<A, B>
type c = DeepMethodReturnType<S, 'stripeCustomer.read'>
Is it possible to access the deep methods of a class using dot notation?是否可以使用点符号访问 class 的深层方法? like
stripeCustomer.read
?喜欢
stripeCustomer.read
吗?
Not using dot notation unfortunately.不幸的是,没有使用点符号。 String literals cannot be concatenated or split at the type level therefore this is impossible.
字符串文字不能在类型级别连接或拆分,因此这是不可能的。
IE This method would rely on splitting the string literal stripeCustomer.read
to stripeCustomer
and read
respectively. IE 此方法将依赖于将字符串文字
stripeCustomer.read
为stripeCustomer
并分别read
。
You can however achieve similar syntax with tuples ["stripeCustomer", "read"]但是,您可以使用元组 ["stripeCustomer", "read"] 实现类似的语法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.