【问题标题】:Namespace 'NodeJS' has no exported member 'Global'. Replace NodeJS.Global with typeof globalThis命名空间“NodeJS”没有导出成员“Global”。将 NodeJS.Global 替换为 typeof globalThis
【发布时间】:2021-10-09 21:27:38
【问题描述】:

typeof globalThis的正确使用方法是什么?请不要走捷径。

interface CustomNodeJsGlobal extends NodeJS.Global {
  foo: {
    bar: string | null
  }
}

这显然会给出:Namespace 'NodeJS' has no exported member 'Global'.ts(2694)

【问题讨论】:

标签: node.js typescript


【解决方案1】:

对于 node.js 16.x,在下面添加应该可以。

declare global {
  namespace NodeJS {
    interface Global {}
  }
}

对于node.js npm i @types/node@^14 或 npm i @types/node@^15 等,

【讨论】:

    猜你喜欢
    • 2021-06-05
    • 2019-10-09
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 2018-03-16
    • 2021-04-05
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多