【发布时间】:2021-03-29 02:34:36
【问题描述】:
是否可以在 TypeScript 中实现装饰器 @important 和实用程序类型 PickImportantProps,使类型 B 在以下示例中变为 { b: string }?
非常感谢提前:)
// decorator
function important(...): ... {
...
}
type PickImportantProps<T> = ...
class A {
a = 'a'
@important()
b = 'b'
}
type B = PickImportantProps<A> // <= should result in { b: string }
【问题讨论】:
-
这不太可能,但您可以查看此问题的答案以获得冗长的解决方法:stackoverflow.com/questions/58039676/…
-
感谢 hlfrmn 的回答以及指向 Stack Overflow 上类似问题的链接。那里的答案和链接的 Github issue 非常有用。顺便说一句:有 50 学分奖励提供有用的答案。如果您有兴趣,请打开此问题的实际答案,因为我不能只为评论支付赏金。
标签: typescript typescript-decorator