【问题标题】:Typescript not loading merged declaration打字稿不加载合并的声明
【发布时间】:2020-11-12 19:36:12
【问题描述】:

升级 typescript 和 express-session 后,tsc 正在加载自定义类型定义存根。

即使我在这里合并了类型声明,我也会收到此错误

我还在 tsconfig.json 中添加了./typing-stubs

"typeRoots": [
      "./typing-stubs",
      "./node_modules/@types"
],

问题是,express 的类型合并正在加载,但 express-session 没有加载

【问题讨论】:

  • 你安装了@types/express 和@types/express-session 吗?
  • 是的。我已经安装了这两个包。 @types/express@4.17.9@types/express-session@1.17.1

标签: typescript typescript-typings express-session


【解决方案1】:

我刚刚在issue得到了快递团队的答复

req.session 声明的接口从@types/express-session 1.17.0 → 1.17.1 由SessionData 更改为Session。你可以看这里https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/express-session

所以解决方法是

declare module "express-session" {
  interface Session {
    user: string;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-19
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2013-01-22
    • 1970-01-01
    相关资源
    最近更新 更多