Imagine I have this simple TypeScript class, Animal.ts
:
export default class Animal {
constructor(public name : string) { }
}
With this tsconfig.json
file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true
},
"files": [
"Animal"
]
}
How can I use the compiled version of this class (compiled by running tsc
) in a javascript file like so:
var Animal = require("./Animal");
var newAnimal = new Animal();
Should I edit something in my tsconfig.json
file? The error I get is:
ReferenceError: Animal is not defined