用Typescript 开发 node.js

文档1:

  1. 运行命令   tsc --init
  2. 修改  tsconfig.json文件
    "outDir": "./bin",                        
    "rootDir": "./src",
  3. 创建 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

猜你喜欢

转载自www.cnblogs.com/Ken-Cai/p/11309072.html