타입스크립트 튜플 Tuple

Jaejun Kim·2023년 1월 10일
0

타입스크립트

목록 보기
5/9
// 배열을 만드는 기능임
// 근데 그 자리에 타입이 지정됨

const tuple_arr: [string, number, string] = ["jaejun", 25, "수원시"]

// 틍징1. 이 이상으로 push는 가능하지만 위에 쓰인 타입만 가능함 
tuple_arr.push(false)  //Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
tuple_arr.push("달리기")

// 특징2 쓰여진 인덱스까지는 타입을 지정할 수 있음
tuple_arr[0] = 1  // Type 'number' is not assignable to type 'string'

배움출처: https://nomadcoders.co/typescript-for-beginners/lobby

0개의 댓글