Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active September 4, 2020 06:58
Show Gist options
  • Save roalcantara/277f2a06c1d1ca79a3e7355639848005 to your computer and use it in GitHub Desktop.
Save roalcantara/277f2a06c1d1ca79a3e7355639848005 to your computer and use it in GitHub Desktop.
Curried Function Sample
interface Todo {
id: number,
text: string,
done: boolean
}
const todo: Todo = {
id: 1,
text: 'learn TS',
done: false
}
const prop =
<T extends string>(key: T) =>
<U extends { [P in T]: U[T] }>(value: U) =>
value[key]
const getID = prop('id')
const id = getID(todo)
Source: https://egghead.io/lessons/typescript-query-properties-with-keyof-and-lookup-types-in-typescript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment