关于在 TypeScript 中键入装饰器的问题

Question about typing decorators in TypeScript

是否可以在 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 }

目前无法在编译时获取此信息。

的答案显示了一种可能的解决方法,它基本上放弃了装饰器语法 (@decoratorName)。