老师好,使用装饰器的时候报错了
来源:2-11 如何借助 TS 的高级类型 解决 2-9 类型自动提示问题

weixin_慕桂英5062843
2023-02-28
视频中这样写没报错,我的代码中提示了错误,,
1回答
-
keviny79
2023-02-28
1.根据提供截图排查第一步:
tsconfig.json 是否设置 true
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"emitDecoratorMetadata": true
2. 核对后把下面代码拷贝过去替换自己的代码:
import 'reflect-metadata'
export function reqProccess(methodType: string) {
return function (reqPath: string) {
return function (targetClassPrototype: any, methodname: string, methodDecri: PropertyDescriptor) {
Reflect.defineMetadata('path', reqPath, targetClassPrototype, methodname)
// console.log(Reflect.getMetadata('path', targetClassPrototype, methodname))
Reflect.defineMetadata('methodType', methodType, targetClassPrototype, methodname)
//console.log(Reflect.getMetadata('methodType', targetClassPrototype, methodname))
}
}
}
const get = reqProccess('get')
const post = reqProccess('post')
const put = reqProccess('put')
const del = reqProccess('delete')
export { get, post, put, del }
3.看看截图的方法提示是否能显示?
如果以上3步弄好后还不行,就加入课程群,把项目发给我看下
012023-03-01
相似问题