问题描述
有没有一种方法可以为Typescript项目中的Javascript文件启用智能感知?如果我从这样的javascript包中导入函数:
Is there a way to enable intellisense for Javascript files in a Typescript project?If I import a function from a javascript package like this:
import foo from "js-package"
并且我在index.js中,我看到了智能感知器在拾取JsDoc注释并列出了该函数采用的参数;但是,如果我在.ts文件中,那么我什么也收不到.如何使用VS Code在.ts文件中启用Js intellisense?
and I'm in index.js, I see the intellisense picking up JsDoc comments and listing the parameters taken by the function;if I'm in a .ts file however, I don't get any of this.How do I enable Js intellisense in .ts files, using VS Code?
这就是发生的情况:
具有讽刺意味的,不是吗?
Ironic, isn't it?
推荐答案
您不需要不需要任何插件.只需添加以下内容即可在 tsconfig.json
中启用typeAcquisition:
You do not need any plugins. Just enable typeAcquisition in your tsconfig.json
by adding:
{
...
"typeAcquisition": {
"enable": true
}
}
这可以自动检测和下载打字稿的定义文件.更改设置时,我通常会重新加载窗口(重新启动vscode),以确保已读取设置.不过,这并不总是必要的.
This enables automatic detection and downloading of definition files for typescript.I often reload the window (restart vscode) when I change the settings, to make sure the settings have been read. This is not always necessary though.
它以前在typeOptions.enableAutoDiscovery下,但已重构为typeAcquisition.enable,如此 Github问题.您仍然可以在此网站上找到对它的引用.我发现很难找到有关typeAcquisition的信息,但是模式证明了它的存在.
It was previously under typingOptions.enableAutoDiscovery, but was refactored to typeAcquisition.enable, as shown on this Github issue. You may still find references to on this websites. I find it harder to find information on typeAcquisition, but the schema proves its existence.
缺少 tsconfig.json
?在此处的最佳答案中创建一个.
这篇关于VS Code:在打字稿项目中启用javascript intellisense的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!