From 558e10c9098769a40645e05e94c1541078184893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miika=20H=C3=A4nninen?= Date: Fri, 15 Dec 2017 15:55:40 +0200 Subject: [PATCH 1/3] Ramda: nth might return undefined If the index points outside the range of the input array, the return value will be undefined. http://ramdajs.com/docs/#nth --- types/ramda/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index cd7e750da7..a40bab0b64 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1149,8 +1149,8 @@ declare namespace R { /** * Returns the nth element in a list. */ - nth(n: number, list: ReadonlyArray): T; - nth(n: number): (list: ReadonlyArray) => T; + nth(n: number, list: ReadonlyArray): T | undefined; + nth(n: number): (list: ReadonlyArray) => T | undefined; /** * Returns a function which returns its nth argument. From 4ab4a67990c54528d6a68d43aae97fa8367ab1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miika=20H=C3=A4nninen?= Date: Fri, 15 Dec 2017 16:00:50 +0200 Subject: [PATCH 2/3] Ramda: Fix splitAt signature - `splitAt` accepts either arrays or strings, not any arbitrary T. - the output will always be an array of two elements, so switched to using the tuple syntax there. - ensures that the overloading after first partial application works http://ramdajs.com/docs/#splitAt fixup splitat --- types/ramda/index.d.ts | 10 ++++++---- types/ramda/ramda-tests.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index a40bab0b64..aa8b8cec66 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1644,10 +1644,12 @@ declare namespace R { /** * Splits a given list or string at a given index. */ - splitAt(index: number, list: T): T[]; - splitAt(index: number): (list: T) => T[]; - splitAt(index: number, list: ReadonlyArray): T[][]; - splitAt(index: number): (list: ReadonlyArray) => T[][]; + splitAt(index: number, list: ReadonlyArray): [T[], T[]]; + splitAt(index: number, list: string): [string, string]; + splitAt(index: number): { + (list: ReadonlyArray): [T[], T[]]; + (list: string): [string, string]; + }; /** * Splits a collection into slices of the specified length. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 321242da00..e25048b768 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1899,6 +1899,7 @@ class Rectangle { const b: number[][] = R.splitAt(1)([1, 2, 3]); // => [[1], [2, 3]] const c: string[] = R.splitAt(5, "hello world"); // => ['hello', ' world'] const d: string[] = R.splitAt(-1, "foobar"); // => ['fooba', 'r'] + const e: string[] = R.splitAt(-1)("foobar"); // => ['fooba', 'r'] }; () => { From 134f9290a240a93404f1801c959079be66ae4261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miika=20H=C3=A4nninen?= Date: Fri, 15 Dec 2017 16:02:29 +0200 Subject: [PATCH 3/3] Ramda: add string overload for splitEvery `splitEvery` works for either an array of any type or a string. http://ramdajs.com/docs/#splitEvery --- types/ramda/index.d.ts | 6 +++++- types/ramda/ramda-tests.ts | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index aa8b8cec66..93c04dc277 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1655,7 +1655,11 @@ declare namespace R { * Splits a collection into slices of the specified length. */ splitEvery(a: number, list: ReadonlyArray): T[][]; - splitEvery(a: number): (list: ReadonlyArray) => T[][]; + splitEvery(a: number, list: string): string[]; + splitEvery(a: number): { + (list: string): string[]; + (list: ReadonlyArray): T[][]; + }; /** * Takes a list and a predicate and returns a pair of lists with the following properties: diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index e25048b768..5d9200070b 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1902,6 +1902,13 @@ class Rectangle { const e: string[] = R.splitAt(-1)("foobar"); // => ['fooba', 'r'] }; +() => { + const a: number[][] = R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]] + const b: number[][] = R.splitEvery(3)([1, 2, 3, 4, 5, 6, 7]); // => [[1, 2, 3], [4, 5, 6], [7]] + const c: string[] = R.splitEvery(3, 'foobarbaz'); // => ['foo', 'bar', 'baz'] + const d: string[] = R.splitEvery(3)('foobarbaz'); // => ['foo', 'bar', 'baz'] +}; + () => { const a: number[][] = R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]] const b: number[][] = R.splitWhen(R.equals(2))([1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]]