类型“Request”上不存在属性“”

2024-04-26

当试图延长Request包中的接口express要添加一些自定义属性,我收到以下打字稿错误:

TS2339: Property '' does not exist on type 'Request<ParamsDictionary>'.

你知道如何解决吗?


自从最近更新其typings https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/express和依赖项,我发现以下内容应该修复您的应用程序中的错误。

In your tsconfig.json

{
  "compilerOptions": {
    //...
    "typeRoots": [
      "./custom_typings",
      "./node_modules/@types"
    ],
  }
// ...
}

在您的自定义打字中

// custom_typings/express/index.d.ts
declare namespace Express {
    interface Request {
        customProperties: string[];
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

类型“Request”上不存在属性“” 的相关文章

随机推荐