ClassDecorator
定义为:
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
我已经这样写了:
export function ClassDecorator(params: any): ClassDecorator {
return function (target) {
Object.seal(target);
Object.seal(target.prototype);
}
}
但是编译器给了我一个错误:
Error:(2, 12) TS2322:Type '(target: any, key: any, descriptor: any) => void' is not assignable to type 'ClassDecorator'.
为什么?
答案 0 :(得分:1)
类型ClassDecorator
被定义为一个带有一个参数的函数,你返回一个带三个参数的函数,这是不兼容的,这就是你得到错误信息的原因。