一、编译选项
- outDir: 编译输入目录
- target: 指定编译的代码版本指标 默认ES3
- watch: 监听模式,只有文件变更,会主动编译
// 命令行模式tsc --outDir ./dist --target es6 ./src/helloTypescript.tstsc -p ./config/xxx.json // -p能够指定配置文件目录// 配置文件形式 tsconfig.json{ compilerOptions:{ target:'es5', outDir:'./dist', watch:true, strictNullCheck:true // 会检测null }, include:["./src/**/*"] // 寻找src下的所有子目录的所有文件}
二、类型零碎
1、类型标注
// 根底类型let title: string = "题目";let n: number = 100;let isOk: boolean = true;// 空和未定义类型 Null和undefinedlet un: undefined;un = 1; // error 只能是undefinedlet o: null;o = 1; // error 只能是null// null和undefined是所有类型的子类型let a: string = '哈哈';a = null; // 能够a = undefined; // 能够// 未赋值状况下,值为undefined// 同时未声明类型 则是any类型let b; // strictNullCheck 会检测null ele是any或者nulllet ele = document.querySelector('#box');const id = ele.id // error ele可能是nulllet obj: object = { x: 1, y: 2}// object只是通知obj是一个对象 有.toString等办法,然而没有阐明有x属性obj.x = 3; // errorlet obj2: { x: number, y: number } = { x: 1, y: 2}obj2.x = 5;// 内置对象类型let d1: Date = new Date();let st = new Set([1, 2]);// 包装器类型// 包装器类型不能赋值给根底类型let str1 = new String('abc');str1 = 'def'; // oklet str2 = 'abc';str2 = new String('def'); // error