Consider the following scenario:
decorator.ts
export function logStuff(target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) {
return {
value: function (...args: any[]) {
args.push("Another argument added");
descriptor.value.apply(target, args);
}
};
}
Shell.ts
// Other imports excluded for simplicity
import logStuff = require("utils/log-decorator");
class Shell extends AnotherClass {
constructor() {
super();
this.fooMethod("arg1");
}
@logStuff
private fooMethod(arg1: string, arg2?: string) {
console.log(`Arguments from original function: ${JSON.stringify(arguments)}`);
}
}
export = Shell;
An issue arises with the message (file path shortened):
Unable to resolve signature of method decorator when called as an expression. Cannot invoke an expression whose type lacks a call signature. Type 'typeof "/utils/log-decorator"' has no compatible call signatures
Moving the function to the top of Shell.ts eliminates errors. Any recommendations on resolving this?