2
votes

I'm using VisualStudio Code, and trying to enable IntelliSense. It seems to be dependent on typings. How can I install these offline? In PowerShell, running

typings search leaflet

returned an error (unsurprising, because I'm offline).

Unable to connect to "https://api.typings.org/search?query=leaflet"

Running that web query on an online computer resulted in a difficult to read JSON file. A further google search resulted in this likely candidate: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/leaflet/index.d.ts

My question has three parts, and I'd appreciate pointers on any of these.

1) How can I figure out what typings I need?

2) Which files do I need to take to the offline computer? Do I just need the d.ts file?

2) Where should this file be installed so that VS Code can read it?

1

1 Answers

3
votes

1) Simply put: if your Visual Studio Code is complaining about not being able to resolve something. Lets say I'm working with jQuery, I'm using $ a lot in my project and it's going to give me an error because it's not Typescript/JavaScript. To resolve this, I create a JSON file to the root of my project called typings.json. It will look like this:

{
  "resolution": "typings/",
  "globalDependencies": {
    "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/index.d.ts"
  }
}

Then in the Terminal tab (CTRL + SHIFT + <) execute the following command: typings install

Now it will download the required typings and put the contents to root/typings/. You'll need to reference it in each file you're using (in this case) jQuery in by adding the following to the top of your TS file: /// <reference path="./typings/globals/jquery/index.d.ts" />

You can also create a definition (.d.ts) file in the root/typings folder and add all the references there so you only have to reference that file.

2) After installing the typings in the previous step, you can copy the typings folder and put it on your offline computer. It's as easy as that. You don't need other files (not even the typings.json file, if you wish).

2) You need to reference definition (d.ts) files at the top of your .ts files.