Skip to content

Instantly share code, notes, and snippets.

@mistakster
Last active December 10, 2024 12:30
Show Gist options
  • Save mistakster/b4dfa8866cb033d20002f8cce7a4617e to your computer and use it in GitHub Desktop.
Save mistakster/b4dfa8866cb033d20002f8cce7a4617e to your computer and use it in GitHub Desktop.
A case for interviewing a TypeScript developer
// The objective is to properly implement `ControlProps`.
const Control = (props: ControlProps) => {
const { variant, ...rest } = props;
if (variant === "button") {
return (
<button {...rest} />
);
} if (variant === "link") {
return (
<a {...rest} />
);
}
return null;
}
const Panel = () => (
<>
<Control variant="button" type="button" onClick={() => {}}>
I am a button
</Control>
<Control variant="link" href="#">
I am an anchor
</Control>
</>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment