table of Contents:
======================================================
Section 1 chat TypeScript
======================================================
1.
2.
3
After compilation, generate js file
4.
======================================================
Section 2 basic types
======================================================
1
2.
3. list array
4. Tuple tuple
5. Enumeration
// 扩展类型 enum 枚举 enum color {Red, Green, Blue}; var c:color = color.Red; console.log(color.Red); // 0 console.log(c); // 0
6. arbitrary value
7. null
void does not allow return return
8. Type assertion
======================================================
Section 3 Interface
======================================================
1. Interface and references
2. interfaces and classes (interfaces, there are what, what class it should be)
======================================================
The first four categories
======================================================
1. Use of class constructor
2.
class 幸福的家庭{} // 新建类 class 儿子 extends 幸福的家庭 {} // 新建类 儿子,继承 类幸福的家庭 class 幸福的家庭{ 父亲 : string, 儿子打招呼(age: number){ // 方法 console.log(`我的父亲是${this.父亲},我今年${age}岁`); }, constructor(fatherName : string) { // 构造函数 this.父亲 = fatherName; } }
Access control modifiers
======================================================
The first five functions
======================================================
1. Have the name of the function
2. anonymous function
Use 1:
Use Method 2:
function dianming(banzhang:string, ...tongxue:string[]) {
console.log('班长:' + banzhang +',同学:' + tongxue.join("、"));
}
let student = dianming('wos','张三', '李四', '王五');
// 班长:wos,同学:张三、李四、王五
======================================================
Section 6 Generics
======================================================
1. Introduction Generics
2. Example 1
3. Example 2
4. Example 3
interface ss<t>{
(arg:t):t
}
function whatis<t>(chr:t):t {
return chr;
}
let num:ss<number> = whatis // num 赋予 ss 接口;运算通过 function 执行
console.log(num(10)); // 10
5. Application of the generic class
======================================================
Section 7 enumeration
======================================================
1 Introduction
2. Example
3. Enumeration Classification
======================================================
Module implements Section 8
======================================================
1. Module Definition
2. Execute function immediately modular
Outer assignment module, the module does not contaminate the inner element