1、创立文件夹
间接创立typescipt文件夹
通过终端创立typescript文件夹
mkdir typescriptcd typescript
2、进入typescript文件夹,初始化npm
npm init
依据提醒回车,这时候文件夹中会生成package.json文件。
3、装置typescript/tslint和NodeJS的类型申明
npm install --save-dev typescript tslint @types/node
tslint是代码规定查看工具,放弃代码格调统一。这时候文件夹中就会生成node_modules文件夹
4、配置tsconfig.json
{ "compilerOptions": { "lib": ["ES2015"], "module": "commonjs", "outDir": "dist", "sourceMap": true, "strict": true, "target": "es2015" }, "include": [ "src" ]}
能够本人新建并配置,或者应用命令初始化,处于typescript目录下,运行以下命令
./node_modules/.bin/tsc --init
根本配置我的项目阐明:include ts文件在哪个文件夹中lib 运行环境包含哪些apimodule ts代码编译成什么模块零碎outDir 编译后的js代码寄存地位stirct 是否开启严格模式target ts编译成js的规范... 有很多配置项具体能够查看其它材料
5、配置tslint.json
{ "defaultSeverity": "error", "extends": [ "tslint:recommended" ], "jsRules": {}, "rules": { "no-console": false }, "rulesDirectory": []}
能够本人新建并配置或者应用命令初始化,处于typescript目录下,运行以下命令
./node_modules/.bin/tslint --init
6、在src目录中创立index.ts文件并输出内容
mkdir srctouch src/index.ts当初整体目录如下typescript----node_modules/----src/ ----index.ts----package.json----tsconfig.json----tslint.json
index.ts...console.log("hello TypeScript")
7、编译
./node_modules/.bin/tsc
这时候文件夹中就会生成dist/index.js
8、运行
node ./dist/index.js
如果中断输入“hello Typescript"那么阐明咱们第一个typescript我的项目配置胜利