Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions types/ramda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
Fn,
IfFunctionsArgumentsDoNotOverlap,
LargestArgumentsList,
mergeArrWithLeft,
} from './tools';

export * from './tools';
Expand Down Expand Up @@ -777,16 +778,18 @@ export function cond<T extends any[], R>(pairs: Array<CondPair<T, R>>): (...args
/**
* Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
*/
export function construct<A extends any[], T>(constructor: { new (...a: A): T } | ((...a: A) => T)): (...a: A) => T;
export function construct<A extends any[], T>(
constructor: { new (...a: A): T } | ((...a: A) => T),
): _.F.Curry<(...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.
*/
export function constructN<A extends any[], T>(
n: number,
export function constructN<A extends any[], T, N extends number>(
n: N,
constructor: { new (...a: A): T } | ((...a: A) => T),
): (...a: Partial<A>) => T;
): _.F.Curry<(...a: mergeArrWithLeft<Tuple<any, N>, A>) => T>;

/**
* Returns `true` if the specified item is somewhere in the list, `false` otherwise.
Expand Down
30 changes: 25 additions & 5 deletions types/ramda/test/construct-tests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import * as R from 'ramda';

(() => {
function Circle(r: number, colors: string) {
() => {
function Circle(this: { r: number; colors: string; area: () => number }, r: number, colors: string) {
this.r = r;
this.colors = colors;
return this;
}

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

const circle = R.construct(Circle);
circle(10, 'red');
})();
// ExpectType (r: number, colors: string) => {r: number, colors: string, area: () => number}
const circleFactory = R.construct(Circle);

// ExpectType {r: number, colors: string, area: () => number}
const circleObject = circleFactory(10, 'red');
};

() => {
class Circle {
constructor(public r: number, public colors: string) {}

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

// ExpectType (r: number, colors: string) => Circle
const circleFactory = R.construct(Circle);

// ExpectType Circle
const circleObject = circleFactory(10, 'red');
};
39 changes: 32 additions & 7 deletions types/ramda/test/constructN-tests.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
import * as R from 'ramda';

(() => {
function Circle(r: number, colors: string) {
() => {
function Circle(this: { r: number; metaInfo?: string; area: () => number }, r: number, metaInfo?: string) {
this.r = r;
this.colors = colors;
this.metaInfo = metaInfo;
return this;
}

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

const circleN = R.constructN(1, Circle);
circleN(10, 'red');
circleN(10);
})();
// $ExpectType Curry<(a_0: number, a_1: string | undefined) => { r: number; metaInfo?: string | undefined; area: () => number; }>
const circleN = R.constructN(2, Circle);

// $ExpectType { r: number; metaInfo?: string | undefined; area: () => number; }
const circleObject0 = circleN(10)('Some additional information');

// $ExpectType { r: number; metaInfo?: string | undefined; area: () => number; }
const circleObject1 = circleN(10, 'Some additional information');
};

() => {
class Circle {
constructor(private readonly r: number, readonly metaInfo?: string) {}

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

// $ExpectType Curry<(a_0: number, a_1: string | undefined) => Circle>
const circleN = R.constructN(2, Circle);

// $ExpectType Circle
const circleObject0 = circleN(10)('Some additional information');

// $ExpectType Circle
const circleObject1 = circleN(10, 'Some additional information');
};
1 change: 0 additions & 1 deletion types/ramda/test/is-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import * as R from 'ramda';
// tslint:disable-next-line:no-unnecessary-class
class Foo {
constructor(arg: string) {}
bar: string;
}

const unknownObject: unknown = {};
Expand Down
4 changes: 2 additions & 2 deletions types/ramda/test/toPairsIn-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class F {
};

class C {
x: 'X';
y: 'Y';
x: 'X' = 'X';
y: 'Y' = 'Y';
}

() => {
Expand Down
2 changes: 1 addition & 1 deletion types/ramda/tools.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ type Intersection<T1, T2> = Intersectable<T1, T2> extends true
*
* <created by @valerii15298>
* */
type mergeArrWithLeft<T1 extends ReadonlyArray<any>, T2 extends ReadonlyArray<any>> = readonly [
export type mergeArrWithLeft<T1 extends ReadonlyArray<any>, T2 extends ReadonlyArray<any>> = readonly [
...{
readonly [Index in keyof T1]: Index extends keyof T2 ? Intersection<T1[Index], T2[Index]> : T1[Index];
},
Expand Down
5 changes: 1 addition & 4 deletions types/ramda/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strict": true,
"baseUrl": "../",
"typeRoots": [
"../"
Expand Down