TypeScript の タプル型
レベル 3137 打鍵
タプルは各要素が特定の型を持つ固定長配列です。
TypeScript のコード
// 要素はちょうど2つ。1つ目がstring、2つ目がnumber1type Pair = [string, number];// ["Alice", 30]は合う。[30, "Alice"]はコンパイルエラー2const person: Pair = ["Alice", 30];// 分割代入で、nameはstring、ageはnumberになる3const [name, age] = person;// 「Alice is 30 years old」を表示する4console.log(`${name} is ${age} years old`);実行結果
Alice is 30 years old
このコードでタイピング練習ができます。記録はランキングに反映されません。
このコードで使う記号
この TypeScript のコードで打つ記号と、出てくる回数です。
;× 4,× 3[× 3]× 3=× 3"× 2{× 2}× 2`× 2$× 2