Skip to content

Instantly share code, notes, and snippets.

@cdaz5
Created August 12, 2022 13:52
Show Gist options
  • Save cdaz5/e173cf0f185659c37d0edec02db18a86 to your computer and use it in GitHub Desktop.
Save cdaz5/e173cf0f185659c37d0edec02db18a86 to your computer and use it in GitHub Desktop.
TypeScript generic example using extends
type Option = { value: string; label: string };
interface DropdownProps<TOption> {
options: ReadonlyArray<TOption>;
onSelection: (option: TOption) => void;
}
function Dropdown<TOption extends Option> ({ options, onSelection }: DropdownProps<TOption>) {
return (
<ul />
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment