Maximus Maximus - 1 year ago 90
TypeScript Question

Class decorator type mismatch error


is defined as:

declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;

I've written it like that:

export function ClassDecorator(params: any): ClassDecorator {
return function (target) {

But the compiler gives me an error:

Error:(2, 12) TS2322:Type '(target: any, key: any, descriptor: any) => void' is not assignable to type 'ClassDecorator'.


Answer Source

The type ClassDecorator is defined to be a function that takes one argument, you return a function that takes three arguments, that is not compatible and that is why you get the error message.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download