Ts学习总结(11/18)——类型

169 阅读1分钟

由于错过了直播,只好自己看文档总结了。

  1. 布尔类型(boolean)
    const type: boolean = true;
    
  2. Number 类型
    const type: number = 1;
    
  3. String 类型
    const type: string = "string";
    
  4.  Enum 类型
    enum People{
      white,
      yellow,
      black,
    }
    
    const person: Color = Peole.white;
    console.log(white); // 0
    
  5. 数组类型(array)
    const arry1: number[] = [1, 2, 3];
    const arry2: Array<number> = [1, 2, 3];
    
  6. 元组类型(tuple)
    const type: [string, number] = ["string", 1];
    
  7. Symbol
    const sym1 = Symbol("string");
    const sym2 = Symbol("string");
    console.log(Symbol("string") === Symbol("string"));
    
  8. any
    const type: any 
    
  9. null 和 undefined
    let type1: undefined = undefined;
    let type2: null = null;