typescript10

Tuple

  • 길이가 정해져 있고, 앞뒤의 타입이 정확한, 다를 수 있는 자료형이다.
let x: [string, number];

x = ["Kdong", 30]; // 길이, 순서도 다 맞아야 한다.

// x = [10, 'Omna'];  // 에러가 뜬다.

x[2] = "world";
// Type '"world"' is not assignable to type 'undefined'.
// Tuple type '[string, number]' of length '2' has no element at index '2'.

const person: [string, number] = ["Kdong", 30];

const [first, second] = person;

// const [first, second, third] = person;
// Tuple type '[string, number]' of length '2' has no element at index '2'.

 

Notion : https://torpid-pasta-de7.notion.site/Basic-Types-7c1eff4fb5f3449e932fb1d157da1f25

'TypeScript > Basic-Types' 카테고리의 다른 글

TypeScript - unknown  (0) 2022.02.07
TypeScript - any  (0) 2022.02.07
TypeScript - Array  (0) 2022.02.07
TypeScript - object  (0) 2022.02.07
TypeScript - null & undefined  (0) 2022.02.07