📐 2.4 TypeScript の基本(型注釈、interface、type、union / intersection)


📝 【要点】


🔧 変数の型注釈(アノテーション)

const count: number = 0;            // ← 数値型
const name: string = 'Alice';       // ← 文字列型
const isActive: boolean = true;     // ← 真偽値

型の名前 意味
number 数値 1, 3.14
string 文字列 "Hello"
boolean true / false true, false

💡 TypeScript では「何が入るか」を明確にできる → 間違いにすぐ気づける!


🛠️ 関数の引数と戻り値にも型をつける

function greet(name: string): string {
  return `Hello, ${name}!`;
}

どこに注目? 書き方
引数の型 name: string
戻り値の型 ): string

🏗️ オブジェクトの型 → interface を使う