Skip to content

Types

@teamsparta/types에서 제공하는 공용 TypeScript 유틸리티 타입입니다.


PartialRecord

모든 키가 선택적(optional)인 Record 타입입니다. Record<K, V>와 달리 모든 키를 제공하지 않아도 됩니다.

API

typescript
type PartialRecord<K extends string | number | symbol, V> = {
  [P in K]?: V;
};

사용 예시

typescript
import type { PartialRecord } from '@teamsparta/types';

type Status = 'active' | 'inactive' | 'pending';

// 모든 Status 키를 제공하지 않아도 됨
const labels: PartialRecord<Status, string> = {
  active: '활성',
  // inactive, pending은 선택적
};

// Record<Status, string>과의 차이
// Record<Status, string>는 모든 키를 반드시 제공해야 함
const allLabels: Record<Status, string> = {
  active: '활성',
  inactive: '비활성',
  pending: '대기중',
};