TypeScript 学习一

根据教程安装 TypeScript 

参考:https://www.runoob.com/typescript/ts-install.html

 

打开vscode

新建文件hello.ts ,保存在 E:\20220318

输入内容

(()=>{
interface Iperson{
    firstName:string
    lastName:string
}
class Person{
    firstName:string
    lastName:string
    fullName:string
    constructor(firstName:string,lastName:string){
        this.firstName=firstName
        this.lastName=lastName
        this.fullName=firstName+'_'+lastName
    }
}
function showFullName(per:Iperson){
    return per.firstName+'_' +per.lastName
}
const per =new Person('发展','科学')
  console.log(showFullName(per))
})()

 

然后用命令运行,切换到 E:\20220318>目录下

 

 输入 

tsc hello.ts

即可发现目录下面多了一个文件

 

 

 

然后输入

node hello.js

可以得到输出结果。

 

 

注意不能直接运行

node hello.ts

也不能直接运行

tsc hello.js

都会报错的。

posted @ 2022-03-20 22:20  剧里局外  阅读(22)  评论(0编辑  收藏  举报