TypeScript 동적 키

Lipton·2023년 11월 14일
0

TypeScript

목록 보기
6/6
{
  "encoding_status": {
    "B000402089": {
      "ocr_update": {
        "event": "ocr_update",
        "status": "success",
        "mcode": "B000402089",
        "text": "안녕하세요",
        "headline": "금융",
        "language": "ko"
      }
    }
  }
}

B000402089와 같이 동적으로 변하는 키를 타입으로 변환하기

type OcrUpdate = {
  event: string;
  status: string;
  mcode: string;
  text: string;
  headline: string;
  language: string;
};

type EncodingStatus = {
  [key: string]: {
    ocr_update: OcrUpdate;
  };
};

EncodingStatus 타입은 문자열 타입의 모든 키를 허용

profile
Web Frontend

0개의 댓글