vscode下搭建type script环境

1.安装vscode

2.安装npm.

2.1 检查npm

$ node -v
v8.12.0
$ npm -v
6.4.1

2.2 安装typescript

$ npm install -g typescript
C:\Users\andrew\AppData\Roaming\npm\tsc -> C:\Users\andrew\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\andrew\AppData\Roaming\npm\tsserver -> C:\Users\andrew\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
+ typescript@3.0.3
added 1 package from 1 contributor in 3.47s

3. 编写第一个ts项目

3.1 用vscode建立ts_first文件夹

3.2 vscode建立tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "noImplicitAny": false,
        "module": "commonjs",
        "removeComments": false,
        "sourceMap": true

        //"sourceMap": false,
        //"outDir": "Golang/TypeScript/",
        //"include":[
        //     "ts"
        // ],
        //"exclude": [
        //     "js"
        // ]
    }
}

3.3 编写ts源文件 ts_first.ts

class Person{
    _name: string;
    constructor(name){
        this._name = name;
    }

    getName(){
        return "get name " + this._name;
    }
}

let person = new Person("i am ch");
console.log(person.getName());


3.3 创建task.json

ctrl+shift+p ——>弹出的命令框中输入“configure tasks”——>选择"tsc: 构建tasks.json"——>自动生成tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        }
    ]
}

3.4 编译

ctrl+shift+B——>选“tsc:构建-tsconfig.json"

生成ts_first.js  和ts_first.js.map

 

3.5 命令行终端执行

PS E:\study\ts\first> tsc .\src\first.ts    
PS E:\study\ts\first> node .\src\first.js
i am Parent-1
i am son     
i am Parent-1
i am daughter
PS E:\study\ts\first> 

4.环境搭建完毕,赶快开始type script学习。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值