构造函数与TypeScript中的装饰器一起传播
在typescript中尝试使用带装饰器的构造函数时出现一些错误,因此给出:构造函数与TypeScript中的装饰器一起传播,typescript,decorator,Typescript,Decorator,在typescript中尝试使用带装饰器的构造函数时出现一些错误,因此给出: 导出函数httpGet(路径?:字符串,…中间件:函数[]){} 其用法如下: class Controller { @httpGet('/:id') async get(ctx: Context) { .... } } 它抛出 Cannot invoke an expression whose type lacks a call signature. 30 @httpGet('/:id') ~~~~
导出函数httpGet(路径?:字符串,…中间件:函数[]){}代码>
其用法如下:
class Controller {
@httpGet('/:id')
async get(ctx: Context) { .... }
}
它抛出
Cannot invoke an expression whose type lacks a call signature.
30 @httpGet('/:id')
~~~~~~~~~~~~~~~~
src/api/Controller.ts(30,3): error TS1241: Unable to resolve signature
of method decorator when called as an expression.
它需要添加方法装饰程序签名:
export function httpGet(path?: string, ...middlewares : Function[]) {
return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
// code goes here
};
}
导出函数httpGet(路径?:字符串,…中间件:函数[]){
返回(目标:对象,属性key:string,描述符:TypedPropertyDescriptor)=>{
//代码在这里
};
}
它需要方法装饰者签名:
export function httpGet(path?: string, ...middlewares : Function[]) {
return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
// code goes here
};
}
导出函数httpGet(路径?:字符串,…中间件:函数[]){
返回(目标:对象,属性key:string,描述符:TypedPropertyDescriptor)=>{
//代码在这里
};
}
好的,我已将其编译,但现在出现运行时错误:@amcdnl在编译到ES5时更改目标。我使用此项目将节点5.5作为目标并编译到ES6。@amcdnl是否使用--harmony
标志运行它?(-rest参数)好的,我已将其编译,但现在出现运行时错误:@amcdnl在编译到ES5时更改目标。我正在使用此项目将节点5.5作为目标并编译到ES6。@amcdnl是否使用--harmony
标志运行它?(-静止参数)