changing namespace of express in typescript

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

changing namespace of express in typescript

问题

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

  1. declare global {
  2. namespace Express {
  3. interface Request {
  4. currentUser?: User;
  5. }
  6. }
  7. }

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

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

英文:

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

  1. declare global {
  2. namespace Express {
  3. interface Request {
  4. currentUser?: User;
  5. }
  6. }
  7. }

Error is:
ES2015 module syntax is preferred over namespaces.

how can i fix this error except change ts rules

答案1

得分: 1

你可以这样做:

  1. declare module 'express' {
  2. export interface Request {
  3. currentUser?: User;
  4. }
  5. }
英文:

You can do it like this:

  1. declare module 'express' {
  2. export interface Request {
  3. currentUser?: User;
  4. }
  5. }

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:

确定