中不存在占用的属性'用户'>"/>
为什么'类型'Request ' 中不存在占用的属性'用户'>
运行ts-node时出现以下错误。
我如下定义了d.ts以使用“ req.user”并应用了tsconfig.json。
Path: src/@types/express/index.d.ts import { User } from '../../model/user/user.interface'; declare global { namespace Express { interface Request { user?: User['employeeId']; } } }
tsconfig.json
{ "compilerOptions": { "typeRoots": [ "./node_modules/@types", "./src/@types" ], "rootDir": ".", "module": "CommonJS", "strict": true, "outDir": "dist", "baseUrl": "./src", "paths": { "*": ["node_modules/@types/*", "src/@types"] }, "esModuleInterop": true }, "include": ["src/**/*.ts"] }
控制器
Path: src/api/posts/controller.ts export const get = (req: Request, res: Response) => { ... const { user } = req; -> occrud Error };
我想念什么?
运行ts-node时出现以下错误。我如下定义d.ts以使用“ req.user”并应用了tsconfig.json。路径:src/@types/express/index.d.ts从'../../ model / ...
回答如下:问题是ts-node
不能接您的类型扩展名,但是tsc
可以。相关的GitHub Issue有更多详细信息,但TL; DR是您必须将客户类型放在node_modules/@types
之前,即:
更多推荐
为什么'类型'Request ' 中不存在占用的属性'用户'>
发布评论