Visual Studio Code Intellisense Typescript不起作用

Visual Studio Code Intellisense Typescript不起作用

问题描述:

我已经尝试了很多年,但无论我做什么,我似乎无法让Visual Studio Code intellisense超越单个文件的打字稿。这是在Windows和Ubuntu上。

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.

我已经包含了一个tsconfig.json文件,但它在项目规模上仍然没有任何智能感知。

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:

tsconfig.json:

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

tasks.json:

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:

tester.ts:

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

在课程测试中,test2未被选中intellisense,即使我将其更改为test.test2。向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?

这是因为你告诉编译器你正在使用外部模块:

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.

如果你正在使用外部模块 - 使用:

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;
}



内部模块



如果您不使用外部模块,则可以使用原始代码,但删除module:commonjs flag。

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