vscode - 用 node_modules 定义替换 typescript 定义

Lok*_*lli 2 javascript typescript visual-studio-code

我是 vscode 的忠实粉丝。这是我的问题,假设我有这样的代码。

const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
Run Code Online (Sandbox Code Playgroud)

当我CMD+Clickexpress(inside require) 或get函数上时,它会将我带到缓存在主文件夹中的打字稿定义。当我清除缓存时,它会将我带到内部定义node_modules,并且缓存将再次构建。而在 中webstorm,没有typescript缓存,它需要我进行node_modules定义。是否可以禁用打字稿定义并使用node_modules定义?

如图所示,当我点击 <code>express</code> 时,它会将我带到 typescript 定义,而不是 <code>node_modules</code> 定义。

如图所示,当我点击express它时,它会将我带到打字稿定义,而不是打字稿node_modules定义。

有一个名为 的内置扩展TypeScript and JavaScript Language Features (vscode.typescript-language-features)。禁用它会起作用吗?我不知道,但我担心我会失去javascript智能感知。

有谁知道吗???

Mat*_*hen 5

“缓存”是由称为“自动类型获取”的功能构建的。您可以通过将 VS Code 的typescript.disableAutomaticTypeAcquisition设置设置为 true 或创建jsconfig.json包含{"typeAcquisition": {"enable": false}}. 您仍然需要手动删除以前下载的类型声明,以便链接将您带到实现 JavaScript 文件。请参阅此答案以获取一些其他相关信息。