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.
main.ts
/// <reference path="Car.ts" />
module Vehicles {
var c = new Vehicles.Car("red");
}
car.ts
module Vehicles {
export class Car {
color: string;
constructor(color: string) {
this.color = color;
console.log("created a new " + color + " car");
}
}
}
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"out": "everything.js main.ts car.ts"
}
}
Update: edited the "out" flag in tsconfig to try and compile main.ts and car.ts into everything.js - this is the last part that is not working: everything.js is not created. Instead, VS Code creates a main.js and a car.js. It seems that the "out" flag is ignored. I have also tried "outFile" with the same result.
outis wrong. It should be just"outFile": "main.js". Try to addexport` in front ofmodule.car.jsbut that's not the main problem. Please post the content of generatedmain.jstoo.filesis not necessary. I don't use the option. We usegulp-typescriptfor compiling.tsfiles because we can compile incrementally the code then which is faster.