I'm trying to write a simple type definition for evolve function from ramda. (https://ramdajs.com/docs/#evolve). Official definition does not work correctly.
type Transformation<State> = {
[Key in keyof State]: (x: State[Key]) => any
}
declare function evolve
<State extends {}, Evolver extends Partial<Transformation<State>>>(evolver: Evolver, state: State):
{[Key in keyof State]: Evolver[Key] extends (...args: any[]) => {} ? ReturnType<Evolver[Key]> : State[Key]}
I'm trying to use that in a generic function:
const foo = <State extends {a: string, b: string}>(state: State) => {
const test = evolve({
a: x => x,
b: x => x
}, state)
}
but I'm getting an error:
Argument of type '{ a: (x: State["a"]) => State["a"]; b: (x: State["b"]) => State["b"]; }' is not assignable to parameter of type 'Partial<Transformation<State>>'.(2345)
It's not clear from the error why it's not assignable, so I don't know how to fix that