[TypeScript] Indexed Access & 여러 타입.
·
프로그래밍 언어/TypeScript
출처: 이정환의 한 입 크기로 잘라먹는 타입스크립트 1. 인덱스드 엑세스 타입 (Indexed Access Type) : 객체 또는 배열에서 특정 요소의 타입을 가져오는데 사용됨.type PostList = { //interface 는 객체타입 정의에만 특화되어있기 때문에 배열을 정의하긴 불편 title: string; content: string; author: { id: number; name: string; age: number; };}[];function printAuthorInfo(author: PostList[number]["author"]) { //인덱스라고 부름 console.log(`${author.name}-${author.id}`);}const post..