배열과 튜플
Arrays in Typescript Typed Arrays : 원소들이 동일한 타입의 값인 것 annotation 없어도 존재하는 원소들을 보고 inference 한다. 빈 배열은 inference할 수 없으므로 any타입이 된다. 1 2 3 4 5 6 7 8 // type annotation const carMarkers: string[] = ['ford', 'toyota', 'chevy']; // Date[] 타입으로 inference const dates = [new Date(), new Date()]; // 2차원. string[][] type이다. const carsByMake = [['f150'], ['corolla'], ['camaro']]; 특징 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // 배열에서 추출시 type inference 한다. const car = carMakers[0]; // string type const myCar = carMakers.pop(); // string type // 배열에 동일하지 않은 type의 값은 추가할 수 없다. carMakers.push(100); // string[]에 number를 넣으면 오류 발생 // 'map, 'forEach', 'reduce' 사용 carMakers.map((car: string): string => { return car.toUpeerCase(); }); // 다수의 type 사용. // const importantDates: (string | Date)[]로 inference 된다. const importantDates = [new Date(), '2030-10-10']; // annotation const importanteDates: (Date | string)[] = [new Date()]; Tuple 각 원소가 기록의 속성을 나타내는 배열과 같은 구조 ...