typescript纯手工编写入门
一、创建目录和项目初始化
1、创建目录
mkdir hello
cd hello
2、项目初始化,创建package文件
npm init
二、安装依赖库
需要安装如下
typescript :用于编译ts文件
tslint:规范代码
@types/node :弄得规范
npm install typescript tslint @types/node --save-dev
结果生成目录如下
三、编写typescript 和tslint的配置文件
需要编写tsconfig.json和tslint.json
1、tsconfig
tsc支持命令
使用tsc --init生成默认配置文件
npx tsc --init
生成默认的tsconfig.json如下
修改默认配置
outDir 设置为‘dist’
2、tslint
tslint支持命令如下
使用 init命令
npx tslint --init
默认生成如下文件
4、编写代码
1、生成代码文件夹
mkdir src
2、编写代码
touch index.ts
console.log('hello world')
5、编译
npx tsc
会在dist文件夹下生成index.js
代码内容如下
说明编译成功
6、运行
node ./dist/index.js
结果如下
圆满结束