简体   繁体   中英

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:

"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 ."

(explained at 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. does it tell me to modify the jsconfig.json in some way.

so how do i get intelisense to work with my bower packages as described in the beginning?

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:

  • 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

i use bower for client packages

my current setup is for developing javascript components and not a website release. 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.

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.

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/

But let's say you are using jquery in your project. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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