安裝:
npm install typescript -g
使用時,新建後綴名爲hello.ts的文件,編譯時用tsc命令
tsc hello.ts
就可以編譯出瀏覽器可解析的js文件。
熱編譯步驟:
- 第一步,tsc --init生成tsconfig.json,改"outDir":"./js";
- 第二步,任務=>運行任務=>監視tsconfig.json
第一個實例helloworld:
function helloworld(name: string) {
console.log(`helloworld!${name}`);
return "helloworld";
}
helloworld("zzhiguang");