diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index ba6908d57c..cb0241bea7 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -55,15 +55,15 @@ declare namespace R { push(x: string): void; } - interface Nested { - [index: string]: Nested | ((value: any) => U); - } - interface Lens { (obj: T): U; set(str: string, obj: T): U; } + type Evolver = + | ((x: T) => T) + | { [K in keyof T]?: Evolver }; + // @see https://gist.github.com/donnut/fd56232da58d25ceecf1, comment by @albrow interface CurriedTypeGuard2 { (t1: T1): (t2: T2) => t2 is R; @@ -567,8 +567,9 @@ declare namespace R { /** * Creates a new object by evolving a shallow copy of object, according to the transformation functions. */ - evolve(transformations: Nested, obj: V): Nested; - evolve(transformations: Nested): (obj: V) => Nested; + evolve(transformations: Evolver, obj: V): V; + evolve(transformations: Evolver): (obj: W) => W; + /* * A function that always returns false. Any passed in parameters are ignored. */ diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 70298f53e6..18a5ed4e7d 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -744,13 +744,13 @@ interface Obj { R.map(double, [1, 2, 3]); // => [2, 4, 6] // functor - const stringFunctor = { - map: (fn: (c: number) => number) => { + const numberFunctor = { + map: (fn: (c: number) => U) => { let chars = "Ifmmp!Xpsme".split(""); - return chars.map((char) => String.fromCharCode(fn(char.charCodeAt(0)))).join("") as any; + return chars.map(char => fn(char.charCodeAt(0))); } }; - R.map((x: number) => x - 1, stringFunctor); // => "Hello World" + R.map((x: number) => x - 1, numberFunctor); // => "Hello World" }; () => { @@ -2199,10 +2199,3 @@ class Why { R.intersperse(0, [1, 2]); // => [1, 0, 2] R.intersperse(0, [1]); // => [1] }; - -{ - const functor = { - map: (fn: (x: string) => string) => functor - }; - R.map(x => x.trim(), functor); -}