Trying to define a new type:
type Union = [1, "one"] | [1, "first"] | [2, "two"]
type GetTuple<T, U> = Extract<T, [U, ...unknown[]]>;
type ObjectFromUnion<T extends Union[0] = Union[0]> = {
number: T,
word: ??
}
Looking to utilize the ObjectFromUnion
type as props for a React component without specifying a generic type, letting it infer based on the values of number
and word
props.
Expected behavior:
<Component number={1} word=/* "one" or "first" */ />
<Component number={2} word=/* "two" */ />
<Component word="one" number=/* {1} */ />
<Component word="first" number=/* {1} */ />
<Component word="two" number=/* {2} */ />