Q:

Why does this TS implementation of "prop" work but mine does not? 

I was looking through some blogs about how to use the keyof feature of typescript to implement a classic function in Ramda/Underscore called prop which returns the value corresponding to a given key on a certain object. 
Example:
prop('length')('hello'); //> 5 | Ramda's curried implementation
prop('length', 'hello'); //> 5 | Underscore and others

I ended up with this implementation (similar to underscore's) that does work:
export function prop<O, K extends keyof O>(key: K, obj: O): O[K] {
  return obj[key];
}

But when I change it to a curried version:
export function prop<O, K extends keyof O>(key: K) {
  return function prop__(obj: O): O[K] {
    return obj[key];
  }
}

I get an error when I try to invoke it as prop('someProp')(someObj); as I hover over prop I get an error that says Argument of type 'someProp' is not assignable to parameter of type 'never' and I really don't know why. 
How can I go about this? 
UPDATE:
Solved!  And now these tests pass:
describe('prop', () => {
  test('should obtain prop value from JSON object', () => {
    const author = { name: 'Luis', age: 25 };
    const getAge = prop('age');

    expect(getAge(author)).toBe(25);
  });

  test('should obtain prop value from known data type', () => {
    expect(prop('length')('lovecraft')).toBe(9);
  });
});

Oh man, I didn't know Record and PropertyKey existed...

A:

You need to move object's generic parameter to the second function (where object is provided as a function's parameter):
export function prop<K extends PropertyKey>(key: K) {
    return <O extends Record<K, any>>(obj: O): O[K] => obj[key];
}

const someObj = { someProp: 'a' };

const someProp = prop('someProp')(someObj) // someProp is string

// Expect error
const someProp1 = prop('someProp1')(someObj) // Property 'someProp1' is missing in type '{ someProp: string; }

Playground

O extends Record<K, any> constraint prevents passing objects that don't have K property

