Last active
February 16, 2021 11:17
-
-
Save paszkowskiDamian/5016ed403982a6cd2fc93f4f86ba0b2c to your computer and use it in GitHub Desktop.
If you need to specify that some type is a key of some object where value is of type string you may use such construct.
This file contains 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
interface Props<T extends Record<K, string>, K extends keyof T> { | |
data: T[]; | |
row: ComponentType<T>; | |
primaryKey: K; | |
} | |
function List<T extends Record<K, string>, K extends keyof T>({ | |
data, | |
row: Row, | |
primaryKey | |
}: Props<T, K>) { | |
return ( | |
<ul> | |
{data.map((element) => ( | |
<Row key={element[primaryKey]} {...element} /> | |
))} | |
</ul> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment