mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-22 12:33:38 +08:00
[ramda] Use mapped types for pluck, prop and props (resolves #21238)
This commit is contained in:
14
types/ramda/index.d.ts
vendored
14
types/ramda/index.d.ts
vendored
@@ -1423,8 +1423,10 @@ declare namespace R {
|
||||
/**
|
||||
* Returns a new list by plucking the same named property off all objects in the list supplied.
|
||||
*/
|
||||
pluck<T>(p: string | number, list: any[]): T[];
|
||||
pluck(p: string | number): <T>(list: any[]) => T[];
|
||||
pluck<P extends string, T>(p: P, list: Array<Record<P, T>>): T[];
|
||||
pluck<T>(p: number, list: Array<{ [k: number]: T }>): T[];
|
||||
pluck<P extends string>(p: P): <T>(list: Array<Record<P, T>>) => T[];
|
||||
pluck(p: number): <T>(list: Array<{ [k: number]: T }>) => T[];
|
||||
|
||||
/**
|
||||
* Returns a new list with the given element at the front, followed by the contents of the
|
||||
@@ -1447,8 +1449,8 @@ declare namespace R {
|
||||
* Returns a function that when supplied an object returns the indicated property of that object, if it exists.
|
||||
* Note: TS1.9 # replace any by dictionary
|
||||
*/
|
||||
prop<T>(p: string, obj: any): T;
|
||||
prop<T>(p: string): (obj: any) => T;
|
||||
prop<P extends string, T>(p: P, obj: Record<P, T>): T;
|
||||
prop<P extends string>(p: P): <T>(obj: Record<P, T>) => T;
|
||||
|
||||
/**
|
||||
* Determines whether the given property of an object has a specific
|
||||
@@ -1487,8 +1489,8 @@ declare namespace R {
|
||||
* The only difference from `prop` is the parameter order.
|
||||
* Note: TS1.9 # replace any by dictionary
|
||||
*/
|
||||
props<T>(ps: string[], obj: any): T[];
|
||||
props(ps: string[]): <T>(obj: any) => T[];
|
||||
props<P extends string, T>(ps: P[], obj: Record<P, T>): T[];
|
||||
props<P extends string>(ps: P[]): <T>(obj: Record<P, T>) => T[];
|
||||
|
||||
/**
|
||||
* Returns true if the specified object property satisfies the given predicate; false otherwise.
|
||||
|
||||
@@ -1535,7 +1535,6 @@ class Rectangle {
|
||||
|
||||
() => {
|
||||
const x: number = R.prop("x", {x: 100}); // => 100
|
||||
const a = R.prop("x", {}); // => undefined
|
||||
};
|
||||
|
||||
() => {
|
||||
@@ -1546,7 +1545,6 @@ class Rectangle {
|
||||
const favorite = R.prop("favoriteLibrary");
|
||||
const favoriteWithDefault = R.propOr("Ramda", "favoriteLibrary");
|
||||
|
||||
const s1 = favorite(alice); // => undefined
|
||||
const s2 = favoriteWithDefault(alice); // => 'Ramda'
|
||||
};
|
||||
|
||||
@@ -1558,7 +1556,6 @@ class Rectangle {
|
||||
|
||||
() => {
|
||||
R.props(["x", "y"], {x: 1, y: 2}); // => [1, 2]
|
||||
R.props(["c", "a", "b"], {b: 2, a: 1}); // => [undefined, 1, 2]
|
||||
|
||||
const fullName = R.compose(R.join(" "), R.props(["first", "last"]));
|
||||
fullName({last: "Bullet-Tooth", age: 33, first: "Tony"}); // => 'Tony Bullet-Tooth'
|
||||
@@ -1859,7 +1856,7 @@ class Rectangle {
|
||||
};
|
||||
|
||||
() => {
|
||||
const sortByNameCaseInsensitive = R.sortBy(R.compose<string, string, string>(R.toLower, R.prop("name")));
|
||||
const sortByNameCaseInsensitive = R.sortBy(R.compose<Record<'name', string>, string, string>(R.toLower, R.prop("name")));
|
||||
const alice = {
|
||||
name: "ALICE",
|
||||
age : 101
|
||||
|
||||
Reference in New Issue
Block a user