Skip to content

Instantly share code, notes, and snippets.

@nulIptr
Created April 27, 2022 04:10
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 nulIptr/7cc0a421a6e91db3336973cae4c07326 to your computer and use it in GitHub Desktop.
Save nulIptr/7cc0a421a6e91db3336973cae4c07326 to your computer and use it in GitHub Desktop.
type StringOnly<T> = { [K in keyof T as T[K] extends string ? K : never]: T[K] };
function useTable<T extends { name: string }>(
records: T[]
) {
return useTableWithCustomKey(records,'name');
}
function useTableForName(records: { name: string }[]) {
return useTableWithCustomKey(records,'name');
}
function useTableWithCustomKey<T>(
records: T[],
keyName: keyof StringOnly<T>
) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment