VS Code:在打字稿项目中启用javascript intellisense

编程入门 行业动态 更新时间:2024-10-26 10:34:15
本文介绍了VS Code:在打字稿项目中启用javascript intellisense的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以为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.

如果使用tsconfig.json,则默认情况下禁用此功能配置文件,但可以将其设置为启用,如进一步概述以下).源

它以前在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

本文发布于:2023-11-17 14:03:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   Code   intellisense   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!