강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

rhkdtjd_12님의 프로필 이미지
rhkdtjd_12

작성한 질문수

실전 연습으로 익히는 고급 타입스크립트 기술

Object value들의 타입을 Union으로 변형 - 문제

유니온으로 해보았습니다

해결된 질문

작성

·

175

0

import { Equal, Expect } from "./helper";

export const Color = {
  Red: "red",
  Green: "green",
  Blue: "blue",
} as const;

type RedGreenBlueValue =
  | (typeof Color)["Red"]
  | (typeof Color)["Blue"]
  | (typeof Color)["Green"];

type tests = [Expect<Equal<RedGreenBlueValue, "red" | "blue" | "green">>];

답변 1

0

애프터캠프님의 프로필 이미지
애프터캠프
지식공유자

export const Color = {
  Red: "red",
  Green: "green",
  Blue: "blue",
} as const;

type ColorType = typeof Color

type RedGreenBlueValue = ColorType[keyof ColorType];

네 그렇게 하셔도 되고 이렇게 해도 될 것 같네요?


rhkdtjd_12님의 프로필 이미지
rhkdtjd_12

작성한 질문수

질문하기