RaelB
RaelB

Reputation: 3481

How to enable IntelliSense for Backbone in VS Code

I am trying to install TypeScript definitions for an example Backbone.js project.

In a project directory, I have issued the following commands:

npm init
npm install typings
typings install dt~backbone --global

This adds an index.d.ts and a typings.json file to a \typings\globals\backbone folder.

enter image description here

The console output is as follows:

enter image description here

As shown, the files are each 1 KB, and VS Code intellisense does not pick up any Backbone definitions. (The project folder does contain a jsconfig.json file.)

Should the "typings install dt~backbone..." command not install the actual backbone type definitions (found in backbone-global.d.ts (17 KB)), and also dependencies like underscore and jquery (each around 140 KB)? Does the stripped reference indicate some type of error?

How do I install these files/definitions (so that VS Code intellisense will work correctly)?

Upvotes: 3

Views: 2491

Answers (1)

Jakub Synowiec
Jakub Synowiec

Reputation: 5969

Foreword

References are always stripped from Typings installation because of their ambiguous nature. The Backbone definitions file doesn't contain the definitions and just references backbone-global and underscore. There is an open issue about this.

Installation and configuration

By default, all JavaScript files opened in Visual Studio Code are treated as independent units. If you want to enable IntelliSense for the whole project remember to place the jsconfig.json file (can be empty) at the root of your project.

To install Typings manager execute npm install typings --global, and then install Backbone definitions with dependancies using following command:

typings install dt~underscore dt~backbone dt~backbone-global --global

You can also add the --save flag to create typings.json file. It's like dependencies part of package.json file but for Typings manager.

Example

I've just tested this quickly and IntelliSense seems to work as supposed after installing all referenced definitions and creating jsconfig.json file.

enter image description here

jsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules",
        "tmp"
    ]
}

typings/index.d.ts

/// <reference path="globals/backbone-global/index.d.ts" />
/// <reference path="globals/backbone/index.d.ts" />
/// <reference path="globals/underscore/index.d.ts" />

Upvotes: 5

Related Questions