TypeScript如何创建一个工程?有源码工程

开始TypeScript开发之前,我们得掌握如何创建一个最初的工程。

下面是创建一个新的工程需要用到的若干语句。

https://www.jianshu.com/p/0e37a793ac3a

https://www.cnblogs.com/xiaoxiaochengxuyuan/p/6137574.html

typescript开发的准备工作:


1.准备工作

1.1安装node.js (www.nodejs.cn)

1.2.安装 typescript

npm install -g typescript

npm i -g typescript

npm i -g nodemon

npm install typings --global

2.typescript里面找不到 'http'模块

npm install -s http

npm install -s @types/http

npm install --save @types/core-js

npm install --save-dev @types/node

npm install –save @types/jquery

===============================

3.开始建立typescript的工程

3.1.初始tsc环境,生成tsconfig.json文件

tsc --init

3.2.初始化 npm环境,生成package.json文件

npm init -y

3.3.vs打开当前目录

code .

3.4.写完ts文件之后,记得build(构建)一下

3.5.打开watch功能

[Terminal]-->[Run Task],选择 watch

如果你的工程没有运行起来,那你要注意你的 task.json文件

在 【Terminal】 -> 【Configure Task】里面,选择 【tsc:build - tscconfig.json】和【tscwatch - tscconfig.json】

这是一个可以参考的task.json文件。

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ],
            "group": "build",
            "label": "tsc: build - tsconfig.json"
        },
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "option": "watch",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "group": "build",
            "label": "tsc: watch - tsconfig.json"
        }
    ]
}

附带一个 工程

https://github.com/liangzai90/websockets-client-and-server

下载下来之后,在vscode里面,点击 view -> terminate ,在这个终端里面执行 npm install

将依赖包下载到本地。

win10 脚本被禁用问题:


set-ExecutionPolicy RemoteSigned

在power shell输入这个命令。

参考地址:https://blog.csdn.net/wqnmlgbsz/article/details/100654258

功能拓展:


1.添加代码检查插件

npm install --save-dev eslint

npm install --save-dev typescript @typescript-eslint/parser

npm install --save-dev @typescript-eslint/eslint-plugin

参考地址: https://ts.xcatliu.com/engineering/lint

或者,直接在vscode的工具栏侧面,搜索 ESLint 插件,安装即可。