You can also hit
CTRL+SPACE and get intellisense.
If you hover over a variable VSCode shows the signature of a function or the type of a variable, if it can be determined.
Follow this series to learn more about what you can do with Visual Studio Code!
angular? Put your cursor on it then click the light bulb ( or
CMD+. ) and choose
Add /// reference to angularjs/angular.d.ts.
VSCode will go and get the typings definition file for Angular and add it to your project, reference it in the file and you instantly have intellisense for Angular! (VSCode grabs the typings files from the Definately Typed repository.)
We can now repeat this by adding jQuery code to a file. Put the cursor on the
CMD+., and pull down the typings file. Now we have jQuery intellisense, too.
Do you see the 2
/// references and how the can accumulate? You can make a single
tsd.d.ts with the npm package named
This produces a
I think the story for this will get even better too, since VSCode uses TypeScript under the covers for its tooling.
The intellisense and editor experience is top notch when using TypeScript. VSCode provides intellisense across multiple files because TypeScript understands the
VSCode provides intellisense for third party libraries, if you include the typings
Intellisense works in well known JSON files too, including
bower.json. It uses schema information and looks up values to find likely matches, where possible.
Here you can see it finding all npm packages that match
Here you can see it finding the most appropriate versions and showing a message about what the versions mean.-->
For more information about the general IntelliSense functionality of Visual Studio, see Using IntelliSense.
TypeScript uses several sources to build up this information:
For a variable or property, the type is typically the type of the value used to initialize it or the most recent value assignment.
For a function, the return type can be inferred from the return statements.
For function parameters, there is currently no inference, but there are ways to work around this using JSDoc or TypeScript .d.ts files (see later sections).
Additionally, there is special inference for the following:
exportsobject, or assignments to the
Where type inference does not provide the desired type information (or to support documentation), type information may be provided explicitly via JSDoc annotations. For example, to give a partially declared object a specific type, you can use the
@type tag as shown below:
As mentioned, function parameters are never inferred. However, using the JSDoc
@param tag you can add types to function parameters as well.
This feature is disabled by default if using a tsconfig.json configuration file, but may be set to enabled as outlined further below.
If you do not wish to use auto-acquisition, disable it by adding a configuration file as outlined below. You can still place definition files for use directly within your project manually.