functional/objects.ts

8 lines
159 B
TypeScript

/**
* Attribute getter
*/
export function attr<K extends string>(
name: K,
): <O extends Record<K, O[K]>>(obj: O) => O[K] {
return (obj) => obj[name];
}