I am currently working on defining a type for the evolve
function from Ramda. The official definition provided does not seem to be functioning 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 attempting to implement this within a generic function:
const foo = <State extends {a: string, b: string}>(state: State) => {
const test = evolve({
a: x => x,
b: x => x
}, state)
}
However, I encountered 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)
The reason behind this error is unclear to me, making it challenging to resolve.