Skip to content

Commit

Permalink
fix(react): button type overloads (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabelloo authored Oct 12, 2021
1 parent 8a3664d commit da8e865
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/react/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export const Button: ButtonComponent = withRef(function Button(
});

export type ButtonProps<T extends 'a' | 'button' = 'button'> = BaseProps &
(T extends 'a' ? AnchorElementProps : ButtonElementProps);
(T extends 'a'
? { href: string } & AnchorElementProps
: { href?: never } & ButtonElementProps);

type ButtonComponent = {
(props: BaseProps & AnchorElementProps, ref: AnchorRef): JSX.Element;
(props: BaseProps & ButtonElementProps, ref: ButtonRef): JSX.Element;
(props: ButtonProps<'a'>, ref: AnchorRef): JSX.Element;
(props: ButtonProps<'button'>, ref: ButtonRef): JSX.Element;
};

type AnchorElementProps = JSX.IntrinsicElements['a'] & { ref?: AnchorRef };
Expand Down

1 comment on commit da8e865

@vercel
Copy link

@vercel vercel bot commented on da8e865 Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.