[TS] Alias, String Literal Types


Type Aliase

  • タイプの別名(インタフェースとは異なる...後で学習)
  •   type Text = string;
      const name: Text = "bae";
    
      type Num = number;
    
      type Student = {
        name: string;
        age: Num;
      };
      const student: Student = {
        name: "bae",
        age: 12,
      };

    String Literal Types

  • 変数として値を指定するタイプ
  •   type Name = "name";
      let myName: Name;
      myName = "name"; // myName에는 "name"만 할당할 수 있음
    
      type JSON = "json";
      const json: JSON = "json";
    
      type Boal = true | false;