mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Ramda - Fix typing of assoc, objOf, and transpose (#16091)
* Fix typing of assoc, objOf, and transpose * Bump language version for Ramda
This commit is contained in:
committed by
Mohamed Hegazy
parent
43d498dfa2
commit
1550dfd1b8
15
types/ramda/index.d.ts
vendored
15
types/ramda/index.d.ts
vendored
@@ -1,7 +1,8 @@
|
||||
// Type definitions for ramda
|
||||
// Project: https://github.com/donnut/typescript-ramda
|
||||
// Definitions by: Erwin Poeze <https://github.com/donnut>, Matt DeKrey <https://github.com/mdekrey>
|
||||
// Definitions by: Erwin Poeze <https://github.com/donnut>, Matt DeKrey <https://github.com/mdekrey>, Liam Goodacre <https://github.com/LiamGoodacre>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
declare var R: R.Static;
|
||||
|
||||
@@ -214,9 +215,9 @@ declare namespace R {
|
||||
/**
|
||||
* Makes a shallow clone of an object, setting or overriding the specified property with the given value.
|
||||
*/
|
||||
assoc<T,U>(prop: string, val: T, obj: U): {prop: T} & U;
|
||||
assoc(prop: string): <T,U>(val: T, obj: U) => {prop: T} & U;
|
||||
assoc<T>(prop: string, val: T): <U>(obj: U) => {prop: T} & U;
|
||||
assoc<T,U,K extends string>(prop: K, val: T, obj: U): Record<K, T> & U;
|
||||
assoc<K extends string>(prop: K): <T,U>(val: T, obj: U) => Record<K, T> & U;
|
||||
assoc<T,K extends string>(prop: K, val: T): <U>(obj: U) => Record<K, T> & U;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1055,8 +1056,8 @@ declare namespace R {
|
||||
/**
|
||||
* Creates an object containing a single key:value pair.
|
||||
*/
|
||||
objOf<T>(key: string, value: T): {string: T};
|
||||
objOf(key: string): <T>(value: T) => {string: T};
|
||||
objOf<T, K extends string>(key: K, value: T): Record<K, T>;
|
||||
objOf<K extends string>(key: K): <T>(value: T) => Record<K, T>;
|
||||
|
||||
/**
|
||||
* Returns a singleton array containing the value provided.
|
||||
@@ -1584,7 +1585,7 @@ declare namespace R {
|
||||
/**
|
||||
* Transposes the rows and columns of a 2D list. When passed a list of n lists of length x, returns a list of x lists of length n.
|
||||
*/
|
||||
transpose<T>(list: any[][]): any[][];
|
||||
transpose<T>(list: T[][]): T[][];
|
||||
|
||||
/**
|
||||
* Removes (strips) whitespace from both ends of the string.
|
||||
|
||||
@@ -965,9 +965,9 @@ type Pair = KeyValuePair<string, number>
|
||||
}
|
||||
|
||||
() => {
|
||||
const a: any[][] = R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]) //=> [[1, 2, 3], ['a', 'b', 'c']]
|
||||
const b: any[][] = R.transpose([[1, 2, 3], ['a', 'b', 'c']]) //=> [[1, 'a'], [2, 'b'], [3, 'c']]
|
||||
const c: any[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]) //=> [[10, 20, 30], [11, 31], [32]]
|
||||
const a: (number | string)[][] = R.transpose<number | string>([[1, 'a'], [2, 'b'], [3, 'c']]) //=> [[1, 2, 3], ['a', 'b', 'c']]
|
||||
const b: (number | string)[][] = R.transpose<number | string>([[1, 2, 3], ['a', 'b', 'c']]) //=> [[1, 'a'], [2, 'b'], [3, 'c']]
|
||||
const c: number[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]) //=> [[10, 20, 30], [11, 31], [32]]
|
||||
}
|
||||
|
||||
() => {
|
||||
@@ -1024,9 +1024,10 @@ type Pair = KeyValuePair<string, number>
|
||||
* Object category
|
||||
*/
|
||||
() => {
|
||||
const a = R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
const b = R.assoc('c')(3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
const c = R.assoc('c', 3)({a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
type ABC = {a: number, b: number, c: number}
|
||||
const a: ABC = R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
const b: ABC = R.assoc('c')(3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
const c: ABC = R.assoc('c', 3)({a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
|
||||
}
|
||||
|
||||
() => {
|
||||
@@ -1296,12 +1297,15 @@ class Rectangle {
|
||||
}
|
||||
|
||||
() => {
|
||||
var matchPhrases = R.compose(
|
||||
R.objOf('must'),
|
||||
R.map(R.objOf('match_phrase'))
|
||||
)
|
||||
const matchPhrases = (xs: string[]) => R.objOf('must',
|
||||
R.map(
|
||||
(x: string) => R.objOf('match_phrase', x),
|
||||
xs
|
||||
)
|
||||
)
|
||||
|
||||
matchPhrases(['foo', 'bar', 'baz']);
|
||||
const out: {must: Array<{match_phrase: string}>} =
|
||||
matchPhrases(['foo', 'bar', 'baz']);
|
||||
}
|
||||
() => {
|
||||
R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
|
||||
|
||||
Reference in New Issue
Block a user