3

I do a lot of work with SharePoint, so I would love to be able to install the SharePoint and Ajax typescript definitions files so I can have Intellisense for them in VS Code.

I found this other question here on SE:

How to Import Intellisense files into vsCode (Visual Studio Code)

but it deals with OSX (I'm on Windows), and apparently you still have to add references at the top of your code files.

Is there a way / place I can install them so that VS Code automatically loads them always and I do not have to reference them at the top of my code files?

Community
  • 1
  • 1
Dylan Cristy
  • 916
  • 11
  • 29

3 Answers3

2

Unfortunately there doesn't seem to be a way to do what I originally wanted, which is have the type definitions loaded whenever I started Code, no matter where I was working.

So the answer is to do something similar to what Nypan suggested, but it turns out it's even easier than that.

According to the documentation on the VS Code website, I don't even need a tsconfig.json file, I can use a jsconfig.json file, and I don't even need to specify the type definition files in the "files" section.

As an example, you can just drop a new type definition .d.ts file into your project folder and VS Code will pick it up automatically.

So, I just have to have the .d.ts files somewhere under the "root" of my workspace, and a jsconfig.json file in the root that is as simple as:

{
    "compilerOptions": {
        "module": "commonjs"
    }
}

and with that I get the IntelliSense for the SharePoint stuff.

Dylan Cristy
  • 916
  • 11
  • 29
  • An empty jsconfig.json file works for me. And the typescript declarations don't have to be in the root of the project, I have them in a /types directory. – Zach Saucier Apr 16 '20 at 15:40
1

You could always create a tsconfig.json file (read more about it here) and place it in the root of your "project".

Something like this:

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "out": "../../built/local/tsc.js",
        "sourceMap": true
    },
    "files": [
        "myDefinition.d.ts",
        "myOtherDefinition.d.ts",
        "SomethingToTranspile.ts",
        "SomethingElseToTranspile.ts",
    ]
}

The above is just an example, read more about it at the link i provided.

Nypan
  • 6,980
  • 3
  • 21
  • 28
0

From the docs: https://code.visualstudio.com/docs/languages/javascript#_automatic-type-acquisition

If you are using Visual Studio Code 1.8+, one alternative is to explicitly list packages to acquire type declaration files for in your jsconfig.json.

"typeAcquisition": {
    "include": [
        "lodash"
    ]
}
John Lee
  • 893
  • 13
  • 14