I am figuring out how to build a typescript app where all classes are saved in separate .ts files. I am using VS Code. The compile task seems to be working correctly (.ts files get transpiled to .js files), but when I load my main.js file into my HTML page I get this javascript error:
Can't find variable: require
My typescript code:
// __________ car.ts __________
class Car {
color: string;
constructor(color: string) {
this.color = color;
console.log("created a new " + color + " car");
}
}
export = Car;
// __________ main.ts __________
import Car = require('car');
class Startup {
public static main(): number {
console.log('Hello World');
var c = new Car("red");
return 0;
}
}
My tsconfig file:
{
"compilerOptions": {
"module": "commonjs",
"sourceMap": true
},
"files": [
"car.ts",
"main.ts"
]
}
What step am I missing here? Why does javascript need something called 'require' ? Or is there another way to work with classes in separate files?