Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Created January 17, 2020 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenLangbroek/bbf63723b3c87d88644eae34cb9a0d01 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/bbf63723b3c87d88644eae34cb9a0d01 to your computer and use it in GitHub Desktop.
interface AsButtonProps {
as: 'button';
onClick?: React.EventHandler<React.MouseEvent>;
formAction?: string;
// [edited for brevity]
}
interface AsAnchorProps {
as: 'a';
href: string;
rel?: string;
// [edited for brevity]
}
export type ButtonProps = AsButtonProps | AsAnchorProps;
/**
* If you now start typing `<Button as="" />, your IDE
* will suggest the 2 possible modes, and when you choose
* 'a', it will suggest & validate the correct props.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment