Piy*_*arg 2 node.js express typescript mern
请帮忙,我收到此错误
src/app/middlewares/authentication.ts:16:17 - 错误 TS2339:属性 'user' 在类型 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' 上不存在。
16 req.user = 用户;
我创建了 .d.ts 文件并将其包含在 tsconfig 文件中。我仍然无法运行此代码
请找到附件截图
小智 31
src/
- types/
- express/
- index.d.ts
Run Code Online (Sandbox Code Playgroud)
import express from "express";
declare global {
namespace Express {
interface Request {
user?: Record<string,any>
}
}
}
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"typeRoots" : ["./src/types", "./node_modules/@types"]
}
}
Run Code Online (Sandbox Code Playgroud)
这应该有效
我之前被困在同样的问题上。这是我解决它的方法。
import * as express from "express"
declare global {
namespace Express {
interface Request {
user? : Record<string,any>
}
}
}
Run Code Online (Sandbox Code Playgroud)
"compilerOptions": {
...other settings,
"typeRoots": ["@types", "node_modules/@types"],
...other settings
}
Run Code Online (Sandbox Code Playgroud)
就是这样。它应该适用于这些更改。
| 归档时间: |
|
| 查看次数: |
2734 次 |
| 最近记录: |