npm install -g typescript
npm install --save-dev typescript tsc-watch
"start": "tsc-watch --onSuccess \"node build/index.js\"",
"build": "tsc"
- Typescript Compile Option
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2015",
"sourceMap": false,
"removeComments": true,
"outDir": "./build"
},
"include": ["src/*"],
"exclude": ["node_modules", "build"]
}
- private, public, protected, readonly
?
: optional
class Book {
private index: number;
readonly name: string;
public desc: string;
constructor(index: number, name: string, desc?: string) {
this.index = index;
this.name = name;
}
}
const numbers: number[] = [1, 2, 3];
const print = (num: number): string => `${num}`;