changing namespace of express in typescript

huangapple go评论59阅读模式
英文:

changing namespace of express in typescript

问题

You can fix this error by using ES2015 module syntax instead of namespaces. Here's the translated code:

declare global {
  namespace Express {
    interface Request {
      currentUser?: User;
    }
  }
}

错误提示:
ES2015 模块语法优于命名空间。

您可以通过使用 ES2015 模块语法来修复此错误,而无需更改 TypeScript 规则。

英文:

I wanna change the express namespace in my typescript file and add another option to it, but eslint get some errors,

declare global {
  namespace Express {
    interface Request {
      currentUser?: User;
    }
  }
}

Error is:
ES2015 module syntax is preferred over namespaces.

how can i fix this error except change ts rules

答案1

得分: 1

你可以这样做:

declare module 'express' {
  export interface Request {
    currentUser?: User;
  }
}
英文:

You can do it like this:

declare module 'express' {
  export interface Request {
    currentUser?: User;
  }
}

huangapple
  • 本文由 发表于 2023年5月7日 19:58:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定