Improved typings for the following functions: countBy, keys, sortBy, toPairs, values

This commit is contained in:
kujon
2017-08-11 15:18:58 +01:00
parent fb18e56681
commit bc930b1b85
2 changed files with 7 additions and 7 deletions

View File

@@ -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<T>(fn: (a: T) => string | number, list: T[]): { [index: string]: number };
countBy<T>(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<T>(x: T): string[];
keys<T>(x: T): Array<keyof T>;
/**
* 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<T>(fn: (a: any) => Ord, list: T[]): T[];
sortBy<T>(fn: (a: T) => Ord, list: T[]): T[];
sortBy(fn: (a: any) => Ord): <T>(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<F, S>(obj: { [k: string]: S } | { [k: number]: S } | any): Array<[F, S]>;
toPairs<T>(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<T>(obj: { [index: string]: T } | any): T[];
values<T>(obj: T): T[keyof T];
/**
* Returns a list of all the properties, including prototype properties, of the supplied

View File

@@ -1557,7 +1557,7 @@ class Rectangle {
};
() => {
const a = R.toPairs<string, number>({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]]
};
() => {