From bc930b1b85c4e3efa1c6492beb26de3db93d5824 Mon Sep 17 00:00:00 2001 From: kujon Date: Fri, 11 Aug 2017 15:18:58 +0100 Subject: [PATCH 1/4] Improved typings for the following functions: countBy, keys, sortBy, toPairs, values --- types/ramda/index.d.ts | 12 ++++++------ types/ramda/ramda-tests.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 5a8ea8f332..35167c5f23 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -422,8 +422,8 @@ declare namespace R { * the list. Note that all keys are coerced to strings because of how * JavaScript objects work. */ - countBy(fn: (a: any) => string | number, list: any[]): any; - countBy(fn: (a: any) => string | number): (list: any[]) => any; + countBy(fn: (a: T) => string | number, list: T[]): { [index: string]: number }; + countBy(fn: (a: T) => string | number): (list: T[]) => { [index: string]: number }; /** * Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. @@ -842,7 +842,7 @@ declare namespace R { * Returns a list containing the names of all the enumerable own * properties of the supplied object. */ - keys(x: T): string[]; + keys(x: T): Array; /** * Returns a list containing the names of all the @@ -1587,7 +1587,7 @@ declare namespace R { /** * Sorts the list according to a key generated by the supplied function. */ - sortBy(fn: (a: any) => Ord, list: T[]): T[]; + sortBy(fn: (a: T) => Ord, list: T[]): T[]; sortBy(fn: (a: any) => Ord): (list: T[]) => T[]; /** @@ -1736,7 +1736,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed to be * consistent across different JS platforms. */ - toPairs(obj: { [k: string]: S } | { [k: number]: S } | any): Array<[F, S]>; + toPairs(obj: T): Array<[keyof T, T[keyof T]]>; /** * Converts an object into an array of key, value arrays. @@ -1916,7 +1916,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed across * different JS platforms. */ - values(obj: { [index: string]: T } | any): T[]; + values(obj: T): T[keyof T]; /** * Returns a list of all the properties, including prototype properties, of the supplied diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index b5fe8d0e5a..4c87113f9a 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1557,7 +1557,7 @@ class Rectangle { }; () => { - const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] + const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] }; () => { From 2ab3885f989738ee18b2985476c6fe4d259d6bdb Mon Sep 17 00:00:00 2001 From: kujon Date: Wed, 6 Sep 2017 14:21:55 +0100 Subject: [PATCH 2/4] Reverted the changes to keys, values and toPairs --- types/ramda/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 35167c5f23..57fb0d0274 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -842,7 +842,7 @@ declare namespace R { * Returns a list containing the names of all the enumerable own * properties of the supplied object. */ - keys(x: T): Array; + keys(x: T): string[]; /** * Returns a list containing the names of all the @@ -1736,7 +1736,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed to be * consistent across different JS platforms. */ - toPairs(obj: T): Array<[keyof T, T[keyof T]]>; + toPairs(obj: { [k: string]: S } | { [k: number]: S } | any): Array<[F, S]>; /** * Converts an object into an array of key, value arrays. @@ -1916,7 +1916,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed across * different JS platforms. */ - values(obj: T): T[keyof T]; + values(obj: { [index: string]: T } | any): T[]; /** * Returns a list of all the properties, including prototype properties, of the supplied From 17a517a1388750ad613b37826913b93145277b75 Mon Sep 17 00:00:00 2001 From: kujon Date: Wed, 6 Sep 2017 14:22:53 +0100 Subject: [PATCH 3/4] Reverted the test changes --- types/ramda/ramda-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 4c87113f9a..b5fe8d0e5a 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1557,7 +1557,7 @@ class Rectangle { }; () => { - const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] + const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] }; () => { From b7d60938396c58d6ace028167df7e12e90a0f8a5 Mon Sep 17 00:00:00 2001 From: kujon Date: Thu, 7 Sep 2017 13:52:39 +0100 Subject: [PATCH 4/4] Required update to tslint rules --- types/ramda/tslint.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/ramda/tslint.json b/types/ramda/tslint.json index 6356421ec0..efa861d7ff 100644 --- a/types/ramda/tslint.json +++ b/types/ramda/tslint.json @@ -1,6 +1,7 @@ { "extends": "dtslint/dt.json", "rules": { - "no-construct": false // Required for R.is function testing + "no-construct": false, // Required for R.is function testing + "no-any-union": false } }