Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

[Feature]: Enable TypeScript Discriminated Union Type Inference in SwitchCase Component #510

Description

@jw-r

Package Scope

  • Add to an existing package

Package name: react

Overview

현재 SwitchCase 컴포넌트에서는 discriminated union 타입을 사용할 때 타입 정보가 손실되어 타입 안전성이 보장되지 않는 문제가 있습니다.

type Quiz = 
  | { type: 'multiple'; options: string[] }
  | { type: 'ox' }

// 현재는 타입 에러가 발생합니다
<SwitchCase
  value={curQuiz.type}
  caseBy={{
    multiple: (
      <div>
        {curQuiz.options} // Error: Property 'options' does not exist on type 'Quiz'
      </div>
    ),
    ox: <div />
  }}
/>

현재 해결을 위해 아래와 같은 수동 타입 체크가 필요한 상황입니다:

{curQuiz.type === 'multiple' && curQuiz.options}

Additional context

  1. 현재 문제점:
  • 타입스크립트의 타입 내로잉(narrowing) 기능을 활용하지 못함
  • 불필요한 타입 가드 코드가 필요함
  • 타입 안전성이 보장되지 않음
  1. 개선 효과:
  • 불필요한 타입 체크 코드 제거
  • 타입스크립트의 타입 시스템 활용도 증가
  • 개발자 경험 향상
  • 타입 안전성 보장

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions