29

I've been trying for ages but I cannot seem to get Visual Studio Code intellisense working beyond a single file for typescript no matter what I do. This is on windows as well as Ubuntu.

I've included a tsconfig.json file but it still doesn't have any intellisense on a project scale.

My current test project contains the following:

tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "out": "test.js"
    },
    "files": [
        "test2.ts",
        "tester.ts"
    ]
}

tasks.json:

{
    "version": "0.1.0",
    "command": "tsc",
    "showOutput": "always",
    "windows": {
        "command": "tsc.exe"
    },
    "args": ["-p", "."],    
    "problemMatcher": "$tsc"
}

test2.ts:

module test
{
    export class test2
    {

    }
}

tester.ts:

module test
{
    export class tester
    {
        public testy: test2;
    }
}

In the class tester test2 isn't picked up by intellisense, even if i change it to test.test2. Adding variables to test2 doesn't help either.

Does anyone know any possible causes as to why it isn't working at all?

4
  • remove the files entirely from tsconfig.js Commented May 23, 2015 at 20:12
  • 1
    Did any of these work? I have problems where initially VS Code was providing intelliense for some libraries (like angular), but when I added new ones (like lodash or moment) it just stops working. It also stopped working entirely when I added new typescript classes for my own code. This is very confusing because the docs suggest this should kinda just work... Commented Jul 15, 2015 at 12:22
  • Not really, it's really buggy on windows and linux. Intellisense seems to work fine with ".d.ts" files as long as there's a tsconfig.json file in the root of the project. Whenever a new ".ts" file is created/added in VSCode it doesn't pick up any intellisense for it unless you close and reopen VSCode . Commented Jul 15, 2015 at 13:59
  • Ok, I eventually got it working by killing all the VSCode related processes manually. Hopefully this becomes more stable as they develop the editor. I started using it because TypeScript support in Sublime (my usual editor) is still so flaky. Commented Jul 16, 2015 at 11:24

13 Answers 13

31

In my case, I had to select the work space version over VSCode version of typescript.

Click on the version number in the blue ribbon at the bottom

enter image description here

And select work space version in the options appearing in the top bar

enter image description here Or the brackets next to the file language: enter image description here

Hope that helps.

Sign up to request clarification or add additional context in comments.

9 Comments

I don't even see the typescript version in the blue ribbon. Any idea why?
Can you see 'Show Status Bar' option under 'View'? That should do the job.
Thank you. Finally came here after hours of searching. Cheers
@azizj1 and others that might still be facing the same issue. Go to extensions and search for @builtin typescript and javascript and enable TypeScript and JavaScript Language Features
you just save my hours, thanks!
I'm using version 1.71.2 of VSCode and the Typescript version doesn't appear at the same place as the screenshot. Instead, I have to click the brackets left to the "Typescript" button and from there I can change the version. Hope it'll save a few minutes of searching!
|
9

It's because you have told the compiler you are using external modules:

"module": "commonjs",

But you are actually trying to use internal modules:

module test

It is best to choose one way or the other.

External Modules

If you are using external modules - use:

test2.ts

export class test2 {

}

tester.ts

import ModuleAlias = require('test2');

export class tester {
    public testy: ModuleAlias.test2;
}

Internal Modules

If you aren't using external modules, you can use your original code, but remove the "module": "commonjs" flag.

{
    "compilerOptions": {
        "out": "test.js"
    },
    "files": [
        "test2.ts",
        "tester.ts"
    ]
}

2 Comments

Removing the module argument doesn't help when i'm using internal modules the intellisense still doesn't work. However I did notice closing the IDE and re-opening then the intellisense kicks in. However if I create a new file then the intellisense stops working for the new file. Removing modules completely doesn't help either. Using external modules isn't an option due to the build system I'm using.
I have added an extra note about how to fix it for internal modules.
9

Lots of good answers here, but for anyone who's reading this now and has been on my level for the past hour:

have you tried restarting VSC?

3 Comments

lol - worked for me. Classic :D
Yes, many times. And restarting the TS server. No option to select Workspace version, TS clearly installed, errors everywhere on all files... It's broken.
should've tried that first, because running Developer: Restart Extension Host didn't help
3

For anyone running into this problem try replacing this:

const { ConnectionPool } = require("mssql");

With this:

import { ConnectionPool } from "mssql"

... for your equivalent library. This solved my issue.

Of course don't forget that you need both the implementation and the @type modules:

npm i mssql
npm i -D @types/mssql

Comments

3

;TLDR

Check the setting typescript.suggest.autoimports and make sure it's set to true.


I've had the same issue, disabled all my extensions but it still wasn't working. I checked the insider version, and it was working on the same project - which for me, meant two things:

  • It's an extension causing the issue (But I've disabled all my extensions, and it still didn't fix my issue, so it can't be this)
  • It's not some tsconfig.json setting, as the insider build is using the same config files.

I checked my user settings file (Clicking on the icon to show you the JSON version of the modified settings), and saw the file was polluted with settings added in there by extensions I haven't used in a while. I started organizing this file and going through the settings, and I eventually found this:

enter image description here

typescript.suggest.autoimports was set to false. I changed that to true, and voila - it started working.

I have no idea what changed this to false (I have an idea that it might be an extension I used, Typescript Importer, but I can't be sure.

Comments

2

Here is another solution in case your issue is the same as mine. I don't see this mentioned here except in a comment by @asdcamargo for the top answer.

Make sure that these @builtin features are enabled either globally or in your workspace:

TypeScript and JavaScript Language Features

TypeScript Language Basics

Comments

1

Intellisense for node_modules folder not work in versions <= 2.0.3 (current).

It will be available in version 2.0.5 (https://github.com/Microsoft/TypeScript/issues/9323)

To temporarily fix you can use the night build: npm install -g typescript@next

It worked for me.

Comments

1

This is not a problem with typescript.

In visual code 1.9 onwards they have security issues.It try to read some data from your windows drive and if you do not have rights then it do not show intellisense.

If you do not have full admin rights on your system then uninstall 1.9.x version and install VSCodeSetup-1.8.1

this works for me.

Comments

1

For me it was the parameter hints which wouldn't show. Intellisense worked but when I opened a function bracket I couldn't see any hints for the parameters.

I tried all the version management suggestions above but it didn't fix it.

Finally I found a setting in VSCodes settings.json under the "[typescript]" key called editor.parameterHints.enabled.

For some reason unknown this was not enabled...why, god why.

enter image description here

Setting it to true now gives me the parameter hints.

enter image description here

Yay.

Comments

1

I had a setting in settings.json that disabled my Typescript Intellisense;

"typescript.validate.enable": false

Hope it helps.

1 Comment

thanks a bunch, this is the exact solution I was looking for.
0

I would update the tsconfig.json to be relative paths:

{
    "compilerOptions": {
        "out": "test.js"
    },
    "files": [
        "./test2.ts",
        "./tester.ts"
    ]
}

Also as metioned by steve don't mix modules (although that wouldn't case an error here). And also, perhaps don't use out : https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md

Comments

0

After upgrading to ESLint, auto-import stopped working.

I finally found the issue here: https://github.com/microsoft/TypeScript/issues/39370#issuecomment-658196303

My .tsconfig had an 'include' and a 'files' attribute. After removing the 'include', it starts working again.

So far I haven't found an approach to add files with include, and have VS Code autocomplete work. Will post back if I do.

Comments

0

Problem I had: TypeScript IntelliSense was not working on character completion in VS Code.

Solution that worked for me:

  1. Open Command Palette using Ctrl+Shift+P (or Cmd+Shift+P on Mac)
  2. Type: Preferences: Open User Settings (JSON)
  3. In the settings.json file, look for this line and delete it: "editor.suggestOnTriggerCharacters": false

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.