- 运行命令
tsc --init
- 修改 tsconfig.json文件
"outDir": "./bin",
"rootDir": "./src", - 创建 src 文件夹, 添加 Hello.ts 文件
class Hello { firstName : string; lastName : string; constructor(fiestName : string, lastName : string) { this.firstName = fiestName; this.lastName = lastName; console.log(`Hello ${fiestName} ${lastName}`) } greeter() { console.log( "欢迎来到typescript的世界,hello" + this.firstName + " " + this.lastName); } } var user = new Hello("王", "小二"); user.greeter();
4. 运行编译命令 tsc
5. 运行程序 node bin/Hello.js