首页 > 解决方案 > Windows 和 macos 上的 VS Code Intellisense 中 NodeJS“全局”对象的类型声明不同

问题描述

我在 OSX 和 Windows 上安装了 VS Code。我在两个系统上都做了非常简单的测试:

创建一个包含以下内容的文件 app.js:

const fs = require('fs');

console.log(global);

然后我 ctrl+单击global符号,我在两个系统上得到的声明是不同的。在 Windows 上,我得到这个:

declare var global: typeof globalThis;

如文件中所定义:C:\Users\user\AppData\Local\Microsoft\Typescript\4.3\node_modules\@types\node\globals.global.d.ts

在 MacOS 上我得到这个:

declare var global: NodeJS.Global & typeof globalThis;

如文件中所定义:Users/user/Library/Caches/typescript/4.4/node_modules/@types/node/globals.global.d.ts

请注意,我之前有过这个4.2版本,但声明在 MacOS 上4.2和. 之间是相同的4.4

谁能告诉我发生了什么以及为什么操作系统之间的声明不同?

标签: node.jstypescriptwindowsmacos

解决方案


推荐阅读