Created
August 12, 2022 13:52
-
-
Save cdaz5/e173cf0f185659c37d0edec02db18a86 to your computer and use it in GitHub Desktop.
TypeScript generic example using extends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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