1
鉴于以下导入时解决打字稿装饰的签名:无法从另一个文件
decorator.ts
export function logStuff(target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) {
return {
value: function (...args: any[]) {
args.push("Another argument pushed");
descriptor.value.apply(target, args);
}
};
}
Shell.ts
// Removed other imports for brevity
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;
我得到这个消息(为简洁起见,缩短了文件路径):
当作为 表达式调用时,无法解析方法装饰器的签名。无法调用其类型缺少呼叫 签名的表达式。类型“的typeof ‘/ utils的/注销装饰’”有没有 兼容调用签名
但是,如果我移动功能Shell.ts的顶部,它编译没有错误。有关如何处理这个问题的任何建议?