Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: enable javascript intellisense in typescript project

Is there a way to enable intellisense for Javascript files in a Typescript project? If I import a function from a javascript package like this:

import foo from "js-package"

and I'm in index.js, I see the intellisense picking up JsDoc comments and listing the parameters taken by the function; if I'm in a .ts file however, I don't get any of this. How do I enable Js intellisense in .ts files, using VS Code?

EDIT: This is what happens:

Typescript: no intellisense

Javascript: intellisense

Ironic, isn't it?

like image 845
Etchelon Avatar asked Jun 22 '18 08:06

Etchelon


People also ask

Does TypeScript have IntelliSense?

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

What is TypeScript IntelliSense?

IntelliSense shows you intelligent code completion, hover information, and signature help so that you can write code more quickly and correctly. VS Code provides IntelliSense for individual TypeScript files as well as TypeScript tsconfig. json projects.


1 Answers

You do not need any plugins. Just enable typeAcquisition in your tsconfig.json by adding:

{
    ...
    "typeAcquisition": {
            "enable": true
    }
}

This enables automatic detection and downloading of definition files for typescript. I often reload the window (restart vscode) when I change the settings, to make sure the settings have been read. This is not always necessary though.

This feature is disabled by default if using a tsconfig.json configuration file, but may be set to enabled as outlined further below). source

It was previously under typingOptions.enableAutoDiscovery, but was refactored to typeAcquisition.enable, as shown on this Github issue. You may still find references to on this websites. I find it harder to find information on typeAcquisition, but the schema proves its existence.

Missing tsconfig.json? Create one following the top answer here.

like image 179
Ben Butterworth Avatar answered Sep 24 '22 01:09

Ben Butterworth