我正在用打字稿写自己的装饰器。目前,我的装饰器看起来像这样:
const Controller = (prefix = ''): ClassDecorator => (target: any): void => {
// My Logic
};
export default Controller;
我的问题是关于ClassDecorator参数的。当前,我正在为any
参数使用target
类型,但此参数需要特定的类型。所以我的问题是这种类型如何命名?
我用谷歌搜索了一段时间,但对此一无所获。
您不需要明确声明Controller的返回类型,因为编译器会推断出它。只要您键入内部函数的参数。.
type MyType = { foo: number }
function f() {
console.log('f(): evaluated')
return function (target: MyType) {
console.log('f(): called' + target.foo)
}
}
``