Search code examples
typescriptintellisensevisual-studio-codetsconfig

Disable intellisense for default typescript libraries in VSCODE


In visual studio code, using typescript, I get unwanted suggestions when using the intellisense/autocomplete feature.

Examples:

HTMLAllCollection
DOMError

etc...

The reason seems to be that intellisense automatically includes all files in

{vscode dir}/resources/app/extensions/node_modules/typescript/lib

Is there any way to disable intellisense for these?

In the end I want intellisense to only include things that are explicitly related to my project.


Solution

  • In order to control which libraries are loaded in your project and are providing intellisense/autocomplete you need to configure lib property [array type] of compilerOptions in your tsconfig.json file.

    If lib property is not configured, TypeScript will automatically load following libraries:

    • For target ES5: DOM, ES5, ScriptHost.
    • For target ES6: DOM, ES6, DOM.Iterable, ScriptHost.

    Example configuration in tsconfig.json file could look like this:

    {
      "compilerOptions": {
        "target": "es5",
        "lib": [
          "es2017"
        ]
      }
    }
    

    This would load only libraries for ECMAScript 2017 intellisense.

    You can read more about compiler options, including lib here: https://www.typescriptlang.org/docs/handbook/compiler-options.html