타입 조작하기
인덱스드 엑세스 타입
interface Post {
title: string;
content: string;
author: {
id: number;
name: string;
age: number;
};
}
function printAuthorInfo(author: Post["author"]) {
console.log(`${author.name} - ${author.id}`);
}
const post: Post = {
title: "게시물 제목",
content: "게시글 본문",
author: {
id: 1,
name: "신봄",
},
};
const author: Post["author"]["id"]; // 속성이 있으므로 사용가능주의
Keyof 연산자
TypeOf와 KeyOf함께 사용하기
Mapped(맵드) 타입
템플릿 리터럴 타입
Last updated