Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union을 복잡하게 쓰면 생기는 문제 #60

Open
youngkyo0504 opened this issue Aug 3, 2024 · 0 comments
Open

Union을 복잡하게 쓰면 생기는 문제 #60

youngkyo0504 opened this issue Aug 3, 2024 · 0 comments

Comments

@youngkyo0504
Copy link
Owner

템플릿 예시입니다.

title:
full_path: src/pages/.md

type MultipleSelect = {
  multiple: true
  value?: string[]
  defaultValue?: string[]
  showCount?: boolean
  maxSelectionCount?: number
} 

type SingleSelect = {
  multiple?: false
  value?: string
  defaultValue?: string
  showCount?: never
  maxSelectionCount?: never
}

type NativeSelect = {
  native: true
  value?: string
  defaultValue?: string
}

type DropdownSelect = {
    native?: false
    placeholder?: string
} & (MultipleSelect | SingleSelect)



type UnionSelect = NativeSelect | DropdownSelect


type OmitBetter<T, K extends string> =  T extends any ? Omit<T, K> : never

type B =Prettify<OmitBetter<UnionSelect, 'native'>>


export type Prettify<T> = {
    [K in keyof T]: T[K]
    // eslint-disable-next-line @typescript-eslint/ban-types
  } & {}

const a :B = {
    value: ['a'],
    placeholder: 'c',
}  

const b: UnionSelect = {
    multiple: true,
    native: false,
    ...a,
    value: ['sf']
} as const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant