Sign In

객체 또는 배열에서 타입 추출하기

작성자
  • 현우
작성시각
카테고리
Empty
상태
Empty
담당자
Empty
참여자
최근활동
현우

typeof

값에서 타입을 뽑아옵니다.
const user = { id: 1, name: 'kim' } as const
type User = typeof user; // { id: number, name: string }

keyof

객체 타입의 키만 뽑아 유니온으로 만든다.
type User = { id: number, name: string };
type UserKey = keyof User; // 꼭 keyof는 타입으로 선언된 타입 선언문에만 사용
// result : 'id' | 'name'

keyof typeof

값에서 타입을 뽑고, 그 타입의 키를 뽑는다.
const STATUS = {
  READY: 'ready',
  DONE: 'done'.
} as const

type STATUS_KEY = keyof typeof STATUS;
// result : 'READY' | 'DONE'
👍
悠悠自適
삼평동 연구원 이야기
운영중인 프로덕트
© 2026 悠悠自適, Inc. All rights reserved.