Visual Studio code uses typings to extend auto-complete functionality

Source: Internet
Author: User



Transferred from: http://blog.csdn.net/liyijun4114/article/details/51658087



Reference Source:


Official Introduction:
Https://code.visualstudio.com/Docs/runtimes/nodejs#_intellisense-and-typings

Gyzhao writes "Visual Studio Code uses typings to implement smart hints":
Http://www.cnblogs.com/IPrograming/p/VsCodeTypings.html

Automatic completion of Vscode


Vscode originally only ES native API with auto-completion function,



But if you use node. js or its require, the related functions are pathetic.



In addition to the process module, PATH, FS, __dirname, and so on, are also not auto-complete. It seems that using __dirname in the lower version also prompts for syntax errors.


Adding auto-completion using typings


Typings official description is a TYPESCRIPT definition manager that integrates the syntax rules for commonly used functions. I don't know if it has anything to do with Microsoft, but it's quite handy.


Official description and instructions for use
Https://www.npmjs.com/package/typings


Vscode can identify typings, so it can be typings as a plug-in to expand the functionality of Vscode. Here's how to use it:


-Configuration Jsconfig.json


Before using typings, you need to configure a file named Jsconfig.json in the Vscode. Configuration method is very simple, randomly select a JS file, Vscode in the lower right corner will pop up a small green light bulb,:

Click in, the top will prompt
"Create a Jsconfig.json to enable richer IntelliSense and code navigation across the entire workspace. "
Selecting Create,vscode will create a Jsconfig.json file with the following content:


{
    // See https://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"
    ]
}


All the required parameters will be set up for us. At this point I am using Vscode v1.2.0 generated Jsconfig, the low version auto-generated configuration may be less than the inside, but does not affect.


-Installation Typings


Using NPM to install typings globally


install -g typings
-Install syntax plugin


To install the node. JS Auto-completion example, use bash or cmd in the project root to enter


typingsinstalldt~node--global


where "dt~" is defined by using the definitelytyped type, vscode can recognize this definition.
You can then see the new Folder "Typings" coming out of the project directory.

Now input process, automatically fill out the ~window may need to restart under Vscode to see the effect of auto-completion.


automatic completion of-express, Lodash, etc.


Similarly, you can use the above method to achieve automatic completion of other modules.


typingsinstalldt~express--globaltypingsinstalldt~lodash--global




//vscode official documentation on the use of express's typings is
Typings install dt~express dt~serve-static dt~express-serve-static-core --global 




Other related to Typings.-Basic Usage


The syntax is copied from Typings's quick Start, and the individual has localized the annotations.


# Install the command line code for Typings.
Npm install typings --global

# Search for the matchings definition of the corresponding module.
Typings search tape

# Find an available typings definition by name.
Typings search --name react

# If you use a separate package of modules:
# or not install global module
# For example, it is not installed on the command line by typing npm install -g typings.
Typings install debug --save

#if it is marked by script
# or is part of a sub-environment
# or when the global teething command is not available:
Typings install dt~mocha --global --save

# Install the typings definition from other versions (such as env or npm).
Typings install env~atom --global --save
Typings install npm~bluebird --save

# Use the file `typings/index.d.ts` (used in the `tsconfig.json` file or defined with `///`).
Cat typings/index.d.ts 





Visual Studio code uses typings to extend auto-complete functionality


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.