sgarcia.dev
sgarcia.dev

Reputation: 6170

In VSCode, How can I enable Angular/Backbone/jQuery intellisense for a project without a package.json?

right now I'm stuck trying to get code autocompletion for a few popular libraries like BackboneJS, Angular and jQuery. The problem, is that the preferred method of enabling this support by the VS Code official docs is unavailable to me (using package.json)

https://code.visualstudio.com/docs/languages/javascript

I followed the steps to the letter and created a jsconfig.json file that looks like this;

{
    "typeAcquisition": {
        "include": [
            "lodash",
            "angular",
            "jquery",
            "underscore"
        ]
    },
    "include": [
        "content/**/*.js"
    ],
    "exclude": [
        "**/node_modules/*",
        "node_modules",
        "**/tmp/*",
        "tmp",
        "**/temp/*",
        "temp",
        "**/bin/*",
        "bin",
        "**/build/*",
        "build"
    ]
}

However, I still am not able to see angular or backbone js autocompletion. Also, it might not help I'm not using commonjs modules (not using require('angular') or import 'backbone') beacuse the current project is built with AMD module system using require js (require(['modulename], function(module) {...}))

Any ideas to how I can somehow get this to work?

Upvotes: 0

Views: 393

Answers (1)

Matt Bierner
Matt Bierner

Reputation: 65463

This is going to be difficult since VS Code's intellisense does not understand AMD style modules.

You may be able to use /// <reference ...> imports and then annotating each the require functions with the proper types:

///<reference types="jquery" />
///<reference types="react" />

require(['jquery', 'react'], function (
    /** @type {$} */jq,
    /** @type {React} */react
) {
   ...
})

This feature request would also help you if it is implemented

Upvotes: 1

Related Questions