Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Intellisense Typescript not working

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?

like image 523
ian.c Avatar asked May 22 '15 10:05

ian.c


2 Answers

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

Hope that helps.

like image 171
Sujit Y. Kulkarni Avatar answered Oct 06 '22 00:10

Sujit Y. Kulkarni


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"
    ]
}
like image 30
Fenton Avatar answered Oct 06 '22 02:10

Fenton