gpt4 book ai didi

javascript - typescript、jsconfig.json、bower.json 和 vs-code 协同工作

转载 作者:行者123 更新时间:2023-11-28 10:48:57 24 4
gpt4 key购买 nike

我最近看到了这篇关于将 Visual Studio Code 与 intelisense 结合使用的文档:

“您还可以通过使用类型定义 .d.ts 文件来获取库的 IntelliSense。DefiniteTyped 是所有主要 JavaScript 库和环境的类型文件存储库。使用 Typings 可以轻松管理类型, TypeScript 定义管理器。例如,typings install --ambient node 安装内置 Node.js 模块的所有typings。 如果您的项目有 jsconfig.json 文件,请确保类型包含在 jsconfig.json 文件位置定义的项目上下文中。”

(解释于https://code.visualstudio.com/Docs/languages/javascript)。

我的问题是我无法让它工作,而且我不确定我是否完全理解以粗体标记的句子。粗体部分告诉我在与 jsconfig.json 相同的文件夹中创建名为typings 或typings.json 的文件夹,或者两者都需要。它是否告诉我以某种方式修改 jsconfig.json?

那么我如何让 intelisense 与我的 Bower 包一起使用,如开头所述?

jsconfig.json

{
// See http://go.microsoft.com/fwlink/?LinkId=759670
// for the documentation about the jsconfig.json format
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules",
"bower_components",
"jspm_packages",
"tmp",
"temp"
],
"typings": "typings/"

}

我使用 node.js npm 来获取全局工具,并且我当前已安装以下全局工具:

  • bower@1.7.9
  • esling@2.9.0
  • generator-aspnet@0.0.93
  • less@2.6.1
  • live-server@0.9.2
  • typings@0.8.1
  • yo@1.7.0

我使用 Bower 作为客户端包

我当前的设置是用于开发 javascript 组件,而不是网站发布。 folder and file structure

最佳答案

所以,粗体这句话的意思是,如果你有一个纯 JavaScript 项目,并且你想在使用 Visual Studio Code 时享受 IntelliSense 的好处,你需要在你的项目根目录下添加一个 jsconfig.json 文件。项目。

此文件可以为空,它可以工作,但是如果您检查文档,您会发现有一些选项可以更改为您的项目。如果您想要的只是 IntelliSense,则空的 jsconfig.json 文件即可完成工作。

接下来,您需要的是类型定义。您可以在打字工具的帮助下添加这些内容。

像这样全局安装它:

npm i -g typings

有一些文档:https://github.com/typings/typings/

但是假设您在项目中使用 jquery。安装打字后,您可以运行命令:

typings i jquery --ambient --save

这将安装 jquery 的类型定义,并且因为您的 javascript 文件中有一个 jsconfig.json 文件,所以在使用 jQuery 时您将具有 IntelliSense。

关于javascript - typescript、jsconfig.json、bower.json 和 vs-code 协同工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37049447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com