问题描述
有没有办法根据 Typescript 中的装饰器来改变函数参数类型?
上下文:
我有这个界面。
export type Bar<T = any> = {
foo: T
taz: string
}
class MyClass {
something(param: Bar) {
// do anything
}
}
const instance = new MyClass()
const foo = { a: 1,b: 2,c: 3 }
instance.something({ foo,taz: 'calling'})
因此,在 something
方法中,我将 foo
作为任何类型。我想要的是根据装饰器中传递的参数键入 foo
,如下所示。
class MyClass {
@inferrerParamType({ a: number,b: number,c: number })
something(param: Bar) {
// do anything
}
}
通过这种方式,智能感知识别函数内 foo
的类型。
我想这样做,因为我将根据通知的数据结构在 param.foo
内部装饰器中应用一些更改。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)