Skip to content

Commit

Permalink
[Ramda] fix construct, juxt, head, tail and last type definiti… (Defi…
Browse files Browse the repository at this point in the history
…nitelyTyped#35905)

* ramda: fix construct and constructN methods

* ramda: fix juxt method

* ramda: fix head, tail and last methods

* ramda: add contributor
  • Loading branch information
Nemo108 authored and RyanCavanaugh committed Jul 1, 2019
1 parent c5a3635 commit 5502326
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
23 changes: 15 additions & 8 deletions types/ramda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// Krantisinh Deshmukh <https://github.com/krantisinh>
// Pierre-Antoine Mills <https://github.com/pirix-gh>
// Brekk Bockrath <https://github.com/brekk>
// Aram Kharazyan <https://github.com/nemo108>
// Jituan Lin <https://github.com/jituanlin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.3
Expand Down Expand Up @@ -1161,13 +1162,13 @@ declare namespace R {
/**
* Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
*/
construct(fn: (...a: any[]) => any): (...a: any[]) => any;
construct<A extends any[], T>(constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: A) => T;

/**
* Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
* The arity of the function returned is specified to allow using variadic constructor functions.
*/
constructN(n: number, fn: (...a: any[]) => any): (...a: any[]) => any;
constructN<A extends any[], T>(n: number, constructor: { new(...a: A): T } | ((...a: A) => T)): (...a: Partial<A>) => T;

/**
* Returns `true` if the specified item is somewhere in the list, `false` otherwise.
Expand Down Expand Up @@ -1492,8 +1493,9 @@ declare namespace R {
* Returns the first element in a list.
* In some libraries this function is named `first`.
*/
head<T>(list: ReadonlyArray<T>): T | undefined;
head(list: string): string;
head(str: string): string;
head(list: []): undefined;
head<T extends any>(list: ReadonlyArray<T>): T;

/**
* Returns true if its arguments are identical, false otherwise. Values are identical if they reference the
Expand Down Expand Up @@ -1668,7 +1670,11 @@ declare namespace R {
/**
* Applies a list of functions to a list of values.
*/
juxt<T, U>(fns: Array<(...args: T[]) => U>): (...args: T[]) => U[];
juxt<A extends any[], R1, R2>(fns: [(...a: A) => R1, (...a: A) => R2]): (...a: A) => [R1, R2];
juxt<A extends any[], R1, R2, R3>(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3]): (...a: A) => [R1, R2, R3];
juxt<A extends any[], R1, R2, R3, R4>(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4]): (...a: A) => [R1, R2, R3, R4];
juxt<A extends any[], R1, R2, R3, R4, R5>(fns: [(...a: A) => R1, (...a: A) => R2, (...a: A) => R3, (...a: A) => R4, (...a: A) => R5]): (...a: A) => [R1, R2, R3, R4, R5];
juxt<A extends any[], U>(fns: Array<(...args: A) => U>): (...args: A) => U[];

/**
* Returns a list containing the names of all the enumerable own
Expand All @@ -1686,8 +1692,9 @@ declare namespace R {
/**
* Returns the last element from a list.
*/
last<T>(list: ReadonlyArray<T>): T | undefined;
last(list: string): string;
last(str: string): string;
last(list: []): undefined;
last<T extends any>(list: ReadonlyArray<T>): T;

/**
* Returns the position of the last occurrence of an item (by strict equality) in
Expand Down Expand Up @@ -2804,8 +2811,8 @@ declare namespace R {
/**
* Returns all but the first element of a list or string.
*/
tail<T>(list: ReadonlyArray<T>): T[];
tail(list: string): string;
tail<T extends any>(list: ReadonlyArray<T>): T[];

/**
* Returns a new list containing the first `n` elements of the given list. If
Expand Down
13 changes: 7 additions & 6 deletions types/ramda/ramda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class F2 {
range(3, 4, 9, -3); // => [-3, 9]

const chopped = R.juxt([R.head, R.last]);
chopped("longstring"); // => ["l", "g"]
chopped([1, 2, 3]); // => [1, 3]
});

function square(x: number) {
Expand Down Expand Up @@ -2322,17 +2322,18 @@ class Rectangle {
};

(() => {
function Circle(r: number) {
function Circle(r: number, colors: string) {
this.r = r;
this.colors = Array.prototype.slice.call(arguments, 1);
this.colors = colors;
}

Circle.prototype.area = function() { return Math.PI * Math.pow(this.r, 2); };

const circleN = R.constructN(2, Circle);
let c1 = circleN(1, "red");
const circleN = R.constructN(1, Circle);
circleN(10, "red");
circleN(10);
const circle = R.construct(Circle);
c1 = circle(1, "red");
circle(10, "red");
})();

/*****************************************************************
Expand Down

0 comments on commit 5502326

Please sign in to comment.