Last active
September 4, 2020 06:58
-
-
Save roalcantara/277f2a06c1d1ca79a3e7355639848005 to your computer and use it in GitHub Desktop.
Curried Function Sample
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
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