Typescript internal module not recognized by VS Code

前端 未结 2 610
鱼传尺愫
鱼传尺愫 2021-01-14 19:30

I am trying to separate my typescript classes in separate files using internal modules. However, the main.ts file will not load or recognize the sub modules.

2条回答
  •  灰色年华
    2021-01-14 19:48

    main.ts

    /// 
    var c = new Car("red");
    

    car.ts

    class Car {
        color: string;
        constructor(color: string) {
            this.color = color;
            console.log("created a new " + color + " car");
        }
    }
    

    tsconfig.json

    {
        "compilerOptions": {
            "sourceMap":  true, 
            "outFile": "main.js"
        },
        "files": [
            "main.ts",
            "car.ts"
        ]
    }
    

    tasks.json

    Kokodoko: I finally found the problem! You have to OMIT the "args" option inside "tasks.json", only then will the arguments in tsconfig.json be used! I found the answer here: github.com/Microsoft/typescript/wiki/tsconfig.json. It says: When input files are specified on the command line, tsconfig.json files are ignored


    For further information about Modules, don't forget to have a look at the TypeScript Handbook

提交回复
热议问题