简体   繁体   English

Typescript,jsconfig.json,bower.json和vs代码一起工作

[英]typescript, jsconfig.json, bower.json and vs-code working together

I recently came accross this piece of documentation for when using visual studio code with intelisense: 我最近在使用带intelisense的Visual Studio代码时遇到了这部分文档:

"You can also get IntelliSense for libraries through the use of type definition .d.ts files. DefinitelyTyped is a repository of typings files for all major JavaScript libraries and environments. The typings are easily managed using Typings, the TypeScript Definition manager. For example typings install --ambient node installs all the typings for the built-in Node.js modules. If your project has a jsconfig.json file, then make sure that typings is contained in the project context defined by the location of the jsconfig.json file ." “您还可以通过使用类型定义.d.ts文件来获取库的IntelliSense。DefinitelyTyped是所有主要JavaScript库和环境的类型文件的存储库。可以使用TypeScript定义管理器Typings轻松管理类型。例如typess install --ambient节点将安装内置Node.js模块的所有类型。 如果您的项目具有jsconfig.json文件,请确保类型包含在jsconfig.json位置定义的项目上下文中。文件 。”

(explained at https://code.visualstudio.com/Docs/languages/javascript ). (在https://code.visualstudio.com/Docs/languages/javascript上解释)。

my problem is i cant get it to work and i am not sure i complete understand the sentence marked in bold. 我的问题是我无法使它正常工作,并且我不确定我是否完全理解粗体标记的句子。 Do the bold part tell me to make folder named typings or typings.json in the same folder as jsconfig.json or is both needed. 粗体部分告诉我要在与jsconfig.json相同的文件夹中创建一个名为Types或Types.json的文件夹,或者两者都需要。 does it tell me to modify the jsconfig.json in some way. 它是否告诉我以某种方式修改jsconfig.json。

so how do i get intelisense to work with my bower packages as described in the beginning? 那么如何如开头所述如何获得智能感知来使用我的凉亭包装?

jsconfig.json 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/"

} }

I use node.js npm for getting global tool and i have currently installed the following as global: 我使用node.js npm来获取全局工具,并且我目前已安装以下全局工具:

  • bower@1.7.9 Bower@1.7.9
  • esling@2.9.0 esling@2.9.0
  • generator-aspnet@0.0.93 generator-aspnet@0.0.93
  • less@2.6.1 少@ 2.6.1
  • live-server@0.9.2 实时服务器@ 0.9.2
  • typings@0.8.1 打字@ 0.8.1
  • yo@1.7.0 yo@1.7.0

i use bower for client packages 我为客户软件包使用Bower

my current setup is for developing javascript components and not a website release. 我当前的设置用于开发javascript组件,而不是网站版本。 folder and file structure 文件夹和文件结构

So, what the sentence in bold is saying is, if you have a pure JavaScript project and you want to have the benefits of IntelliSense when using Visual Studio Code, you need to add a jsconfig.json file on the root of your project. 因此,粗体字表示的是,如果您有一个纯JavaScript项目,并且希望在使用Visual Studio Code时享受IntelliSense的好处,则需要在项目的根目录中添加jsconfig.json文件。

This file can be empty, it will work, but if you check the docs you'll see that there are some options you can change to your project. 该文件可以为空,可以使用,但是如果您查看文档,将会看到可以更改项目的某些选项。 If all you want is IntelliSense an empty jsconfig.json file will do the work. 如果您只需要IntelliSense,则将执行一个空jsconfig.json文件。

Next, what you need is the type definitions. 接下来,您需要的是类型定义。 You can add those with the help of the typings tool. 您可以在打字工具的帮助下添加它们。

Install it globally like this: 像这样全局安装:

npm i -g typings

There are some docs on: https://github.com/typings/typings/ 上有一些文档: https//github.com/typings/typings/

But let's say you are using jquery in your project. 但是,假设您在项目中使用jquery。 After installing typings you could run the command: 安装类型后,您可以运行以下命令:

typings i jquery --ambient --save

This would install the type definitions for jquery, and because you have a jsconfig.json file, in your javascript files, you'd have IntelliSense when using jQuery. 这将安装jquery的类型定义,并且由于您有jsconfig.json文件,因此在javascript文件中,使用jQuery时将具有IntelliSense。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM