Skip to content

Commit

Permalink
Add distributive condition to Assign util
Browse files Browse the repository at this point in the history
  • Loading branch information
jjenzz committed Oct 1, 2021
1 parent b206022 commit 54bf0c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/react/tests/types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,19 @@ void function Test() {
}} />
)
}

/* -------------------------------------------------------------------------------------------------
* Issue #821
* -----------------------------------------------------------------------------------------------*/

type UnionProps = { type: 'single', collapsible: boolean; } | { type: 'multiple' };
const UnionComponent: React.FC<UnionProps> = () => null
const StyledUnionComponent = styled(UnionComponent, {})

void function Test() {
<>
<StyledUnionComponent type="single" collapsible />
{/* @ts-expect-error */}
<StyledUnionComponent type="multiple" collapsible />
</>
}
2 changes: 1 addition & 1 deletion packages/react/types/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export type Prefixed<K extends string, T> = `${K}${Extract<T, boolean | number | string>}`

/** Returns an object from the given object assigned with the values of another given object. */
export type Assign<T1 = {}, T2 = {}> = Omit<T1, keyof T2> & T2
export type Assign<T1 = {}, T2 = {}> = T1 extends any ? Omit<T1, keyof T2> & T2 : never

/** Returns a widened value from the given value. */
export type Widen<T> =
Expand Down

0 comments on commit 54bf0c8

Please sign in to comment.