---
title: "创建typescript项目"
author: "jatter"
date: "2018-05-01T15:13:05Z"
tags: []
categories: ["Web前端"]
slug: "typescript"
draft: false
lastmod: "2018-05-02T14:44:51Z"
id: 2421784
url: "https://jatter.iteye.com/blog/2421784"
---

#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)=&gt;{

    "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