#cd 一个目录
npm init #初始化
npm install typescript --save-dev
#创建目录结构
projectRoot
├── src
│ ├── file1.js
│ └── file2.js
├── built
└── tsconfig.json
#配置文件tsconfig.json
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "es5"
},
"include": [
"./src/**/*"
]
}
#在src目录下,新建一个index.ts文件,代码如下:
let showMe = (name:string,age:number)=>{
"use strict";
return "我的名字是:"+name+",我的年龄是:"+age;
}
// 调用函数
console.log(showMe("lily",19));
#修改package.json,在scripts段添加:
"scripts": {
"b": "tsc && node ./built/index"
},
#在终端执行
npm run b
$ sudo npm install -g @angular/cli