Skip to content

Commit

Permalink
fix(react): unions in prop types are not resolved (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
dewey92 committed Sep 22, 2021
1 parent 4662afb commit d0f9c78
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/react/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ const warnIfInvalid = (value: any, componentName: string) => {
// If styled wraps custom component, that component should have className property
function styled<TConstructor extends React.FunctionComponent<any>>(
tag: TConstructor extends React.FunctionComponent<infer T>
? T extends { className?: string }
? [T] extends [{ className?: string }]
? TConstructor
: never
: never
): ComponentStyledTag<TConstructor>;
function styled<T>(
tag: T extends { className?: string } ? React.ComponentType<T> : never
tag: [T] extends [{ className?: string }] ? React.ComponentType<T> : never
): ComponentStyledTag<T>;
function styled<TName extends keyof JSX.IntrinsicElements>(
tag: TName
Expand Down Expand Up @@ -155,7 +155,7 @@ function styled(tag: any): any {
}

type StyledComponent<T> = StyledMeta &
(T extends React.FunctionComponent<any>
([T] extends [React.FunctionComponent<any>]
? T
: React.FunctionComponent<T & { as?: React.ElementType }>);

Expand All @@ -177,7 +177,7 @@ type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <

type ComponentStyledTag<T> = <
OwnProps = {},
TrgProps = T extends React.FunctionComponent<infer TProps> ? TProps : T
TrgProps = [T] extends [React.FunctionComponent<infer TProps>] ? TProps : T
>(
strings: TemplateStringsArray,
// Expressions can contain functions only if wrapped component has style property
Expand All @@ -188,7 +188,7 @@ type ComponentStyledTag<T> = <
>
: StaticPlaceholder[]
) => keyof OwnProps extends never
? T extends React.FunctionComponent<any>
? [T] extends [React.FunctionComponent<any>]
? StyledMeta & T
: StyledComponent<TrgProps>
: StyledComponent<OwnProps & TrgProps>;
Expand Down

0 comments on commit d0f9c78

Please sign in to comment.