Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
fix(tempalte): list append-like operations should not affect types
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Jul 1, 2017
1 parent 9ed1f42 commit 12988ac
Show file tree
Hide file tree
Showing 27 changed files with 210 additions and 63 deletions.
13 changes: 10 additions & 3 deletions snapshots/adjust.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {Morphism} from '../ramda/dist/src/$types';
import * as R_adjust from '../ramda/dist/src/adjust';

declare const string_to_string: Morphism<string, string>;
declare const string_to_number: Morphism<string, number>;
declare const string_array: string[];
declare const number: number;

// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'.
R_adjust(string_to_number)(number, string_array);
// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'.
R_adjust(string_to_number, number)(string_array);
// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'.
R_adjust(string_to_number, number, string_array);
// @dts-jest:pass -> string[]
R_adjust(string_to_string)(number, string_array);
// @dts-jest:pass -> string[]
R_adjust(string_to_string, number)(string_array);
// @dts-jest:pass -> string[]
R_adjust(string_to_string, number, string_array);
9 changes: 7 additions & 2 deletions snapshots/append.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as R_append from '../ramda/dist/src/append';

declare const string: string;
declare const number: number;
declare const number_array: number[];

// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
R_append(string)(number_array);
// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
R_append(string, number_array);
// @dts-jest:pass -> number[]
R_append(number)(number_array);
// @dts-jest:pass -> number[]
R_append(number, number_array);
14 changes: 11 additions & 3 deletions snapshots/insert.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import * as R_insert from '../ramda/dist/src/insert';

declare const object: object;
declare const object_array: object[];
declare const string: string;
declare const number: number;

// @dts-jest:pass -> <U>(list: U[] | ArrayLike<U>) => (string | U)[]
// @dts-jest:pass -> (list: string[] | ArrayLike<string>) => string[]
R_insert(number, string);
// @dts-jest:pass -> (string | object)[]
// @dts-jest:fail -> Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
R_insert(number, string, object_array);
// @dts-jest:pass -> (string | object)[]
// @dts-jest:fail -> Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
R_insert(number)(string)(object_array);

// @dts-jest:pass -> (list: object[] | ArrayLike<object>) => object[]
R_insert(number, object);
// @dts-jest:pass -> object[]
R_insert(number, object, object_array);
// @dts-jest:pass -> object[]
R_insert(number)(object)(object_array);
10 changes: 7 additions & 3 deletions snapshots/insertAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ declare const object_array: object[];
declare const string_array: string[];
declare const number: number;

// @dts-jest:pass -> <U>(list: U[] | ArrayLike<U>) => (string | U)[]
// @dts-jest:pass -> (list: string[] | ArrayLike<string>) => string[]
R_insertAll(number, string_array);
// @dts-jest:pass -> (string | object)[]
// @dts-jest:fail -> Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
R_insertAll(number, string_array, object_array);
// @dts-jest:pass -> (string | object)[]
// @dts-jest:fail -> Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
R_insertAll(number)(string_array)(object_array);
// @dts-jest:pass -> string[]
R_insertAll(number, string_array, string_array);
// @dts-jest:pass -> string[]
R_insertAll(number)(string_array)(string_array);
9 changes: 7 additions & 2 deletions snapshots/prepend.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as R_prepend from '../ramda/dist/src/prepend';

declare const string: string;
declare const number: number;
declare const number_array: number[];

// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
R_prepend(string)(number_array);
// @dts-jest:pass -> (string | number)[]
// @dts-jest:fail -> Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
R_prepend(string, number_array);
// @dts-jest:pass -> number[]
R_prepend(number)(number_array);
// @dts-jest:pass -> number[]
R_prepend(number, number_array);
10 changes: 5 additions & 5 deletions snapshots/ramda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ import * as R from '../ramda/dist/index';
R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
// @dts-jest:pass -> string[]
R.append('tests')(['write', 'more']); //=> ['write', 'more', 'tests']
// @dts-jest:pass -> string[]
// @dts-jest:pass -> "tests"[]
R.append('tests', []); //=> ['tests']
// @dts-jest:pass -> (string | string[])[]
R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
// @dts-jest:pass -> (string | string[])[]
R.append(['tests'])(['write', 'more']); //=> ['write', 'more', ['tests']]
// @dts-jest:fail -> Argument of type 'string[]' is not assignable to parameter of type 'List<string[]>'.
R.append(['tests'], ['write', 'more']); //=> different types are not allowed // ['write', 'more', ['tests']]
// @dts-jest:fail -> Argument of type 'string[]' is not assignable to parameter of type 'List<string[]>'.
R.append(['tests'])(['write', 'more']); //=> different types are not allowed // ['write', 'more', ['tests']]
})();

// @dts-jest:group apply
Expand Down
11 changes: 8 additions & 3 deletions snapshots/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import * as R_update from '../ramda/dist/src/update';

declare const string_array: string[];
declare const boolean: boolean;
declare const string: string;
declare const number: number;

// @dts-jest:pass -> <U>(list: U[] | ArrayLike<U>) => (boolean | U)[]
// @dts-jest:pass -> (list: boolean[] | ArrayLike<boolean>) => boolean[]
R_update(number, boolean);
// @dts-jest:pass -> (string | boolean)[]
// @dts-jest:fail -> Argument of type 'string[]' is not assignable to parameter of type 'List<boolean>'.
R_update(number)(boolean)(string_array);
// @dts-jest:pass -> (string | boolean)[]
// @dts-jest:fail -> Argument of type 'string[]' is not assignable to parameter of type 'List<boolean>'.
R_update(number, boolean, string_array);
// @dts-jest:pass -> string[]
R_update(number)(string)(string_array);
// @dts-jest:pass -> string[]
R_update(number, string, string_array);
2 changes: 1 addition & 1 deletion templates/adjust.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List, Morphism} from './$types';

export function $<T, U>(fn: Morphism<T, U>, index: number, list: List<T>): (T | U)[];
export function $<T>(fn: Morphism<T, T>, index: number, list: List<T>): T[];
2 changes: 1 addition & 1 deletion templates/append.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List} from './$types';

export function $<T, U>(value: T, list: List<U>): (T | U)[];
export function $<T>(value: T, list: List<T>): T[];
2 changes: 1 addition & 1 deletion templates/insert.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List} from './$types';

export function $<T, U>(index: number, value: T, list: List<U>): (T | U)[];
export function $<T>(index: number, value: T, list: List<T>): T[];
2 changes: 1 addition & 1 deletion templates/insertAll.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List} from './$types';

export function $<T, U>(index: number, values: List<T>, list: List<U>): (T | U)[];
export function $<T>(index: number, values: List<T>, list: List<T>): T[];
2 changes: 1 addition & 1 deletion templates/prepend.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List} from './$types';

export function $<T, U>(value: T, list: List<U>): (T | U)[];
export function $<T>(value: T, list: List<T>): T[];
2 changes: 1 addition & 1 deletion templates/update.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {List} from './$types';

export function $<T, U>(index: number, value: T, list: List<U>): (T | U)[];
export function $<T>(index: number, value: T, list: List<T>): T[];
15 changes: 12 additions & 3 deletions tests/__snapshots__/adjust.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_adjust(string_to_number)(number, string_array) 1`] = `"(string | number)[]"`;
exports[`R_adjust(string_to_number)(number, string_array) 1`] = `
"Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'.
Type 'number' is not assignable to type 'string'."
`;

exports[`R_adjust(string_to_number, number)(string_array) 1`] = `"(string | number)[]"`;
exports[`R_adjust(string_to_number, number)(string_array) 1`] = `"Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'."`;

exports[`R_adjust(string_to_number, number, string_array) 1`] = `"(string | number)[]"`;
exports[`R_adjust(string_to_number, number, string_array) 1`] = `"Argument of type 'Morphism<string, number>' is not assignable to parameter of type 'Morphism<string, string>'."`;

exports[`R_adjust(string_to_string)(number, string_array) 1`] = `"string[]"`;

exports[`R_adjust(string_to_string, number)(string_array) 1`] = `"string[]"`;

exports[`R_adjust(string_to_string, number, string_array) 1`] = `"string[]"`;
16 changes: 14 additions & 2 deletions tests/__snapshots__/append.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_append(string)(number_array) 1`] = `"(string | number)[]"`;
exports[`R_append(number)(number_array) 1`] = `"number[]"`;

exports[`R_append(string, number_array) 1`] = `"(string | number)[]"`;
exports[`R_append(number, number_array) 1`] = `"number[]"`;

exports[`R_append(string)(number_array) 1`] = `
"Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
Type 'number[]' is not assignable to type 'ArrayLike<string>'.
Index signatures are incompatible.
Type 'number' is not assignable to type 'string'."
`;
exports[`R_append(string, number_array) 1`] = `
"Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
Type 'number[]' is not assignable to type 'ArrayLike<string>'."
`;
20 changes: 17 additions & 3 deletions tests/__snapshots__/insert.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_insert(number)(string)(object_array) 1`] = `"(string | object)[]"`;
exports[`R_insert(number)(object)(object_array) 1`] = `"object[]"`;

exports[`R_insert(number, string) 1`] = `"<U>(list: U[] | ArrayLike<U>) => (string | U)[]"`;
exports[`R_insert(number)(string)(object_array) 1`] = `
"Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
Type 'object[]' is not assignable to type 'ArrayLike<string>'."
`;
exports[`R_insert(number, string, object_array) 1`] = `"(string | object)[]"`;
exports[`R_insert(number, object) 1`] = `"(list: object[] | ArrayLike<object>) => object[]"`;
exports[`R_insert(number, object, object_array) 1`] = `"object[]"`;
exports[`R_insert(number, string) 1`] = `"(list: string[] | ArrayLike<string>) => string[]"`;
exports[`R_insert(number, string, object_array) 1`] = `
"Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
Type 'object[]' is not assignable to type 'ArrayLike<string>'.
Index signatures are incompatible.
Type 'object' is not assignable to type 'string'."
`;
18 changes: 15 additions & 3 deletions tests/__snapshots__/insertAll.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_insertAll(number)(string_array)(object_array) 1`] = `"(string | object)[]"`;
exports[`R_insertAll(number)(string_array)(object_array) 1`] = `
"Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
Type 'object[]' is not assignable to type 'ArrayLike<string>'."
`;
exports[`R_insertAll(number, string_array) 1`] = `"<U>(list: U[] | ArrayLike<U>) => (string | U)[]"`;
exports[`R_insertAll(number)(string_array)(string_array) 1`] = `"string[]"`;
exports[`R_insertAll(number, string_array, object_array) 1`] = `"(string | object)[]"`;
exports[`R_insertAll(number, string_array) 1`] = `"(list: string[] | ArrayLike<string>) => string[]"`;
exports[`R_insertAll(number, string_array, object_array) 1`] = `
"Argument of type 'object[]' is not assignable to parameter of type 'List<string>'.
Type 'object[]' is not assignable to type 'ArrayLike<string>'.
Index signatures are incompatible.
Type 'object' is not assignable to type 'string'."
`;
exports[`R_insertAll(number, string_array, string_array) 1`] = `"string[]"`;
16 changes: 14 additions & 2 deletions tests/__snapshots__/prepend.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_prepend(string)(number_array) 1`] = `"(string | number)[]"`;
exports[`R_prepend(number)(number_array) 1`] = `"number[]"`;

exports[`R_prepend(string, number_array) 1`] = `"(string | number)[]"`;
exports[`R_prepend(number, number_array) 1`] = `"number[]"`;

exports[`R_prepend(string)(number_array) 1`] = `
"Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
Type 'number[]' is not assignable to type 'ArrayLike<string>'.
Index signatures are incompatible.
Type 'number' is not assignable to type 'string'."
`;
exports[`R_prepend(string, number_array) 1`] = `
"Argument of type 'number[]' is not assignable to parameter of type 'List<string>'.
Type 'number[]' is not assignable to type 'ArrayLike<string>'."
`;
14 changes: 11 additions & 3 deletions tests/__snapshots__/ramda-tests.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ exports[`append R.append('tests')(['write', 'more']) 1`] = `"string[]"`;

exports[`append R.append('tests', ['write', 'more']) 1`] = `"string[]"`;

exports[`append R.append('tests', []) 1`] = `"string[]"`;
exports[`append R.append('tests', []) 1`] = `"\\"tests\\"[]"`;

exports[`append R.append(['tests'])(['write', 'more']) 1`] = `"(string | string[])[]"`;
exports[`append R.append(['tests'])(['write', 'more']) 1`] = `
"Argument of type 'string[]' is not assignable to parameter of type 'List<string[]>'.
Type 'string[]' is not assignable to type 'ArrayLike<string[]>'."
`;

exports[`append R.append(['tests'], ['write', 'more']) 1`] = `"(string | string[])[]"`;
exports[`append R.append(['tests'], ['write', 'more']) 1`] = `
"Argument of type 'string[]' is not assignable to parameter of type 'List<string[]>'.
Type 'string[]' is not assignable to type 'ArrayLike<string[]>'.
Index signatures are incompatible.
Type 'string' is not assignable to type 'string[]'."
`;

exports[`apply R.apply(Math.max)(nums) 1`] = `"number"`;

Expand Down
18 changes: 15 additions & 3 deletions tests/__snapshots__/update.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_update(number)(boolean)(string_array) 1`] = `"(string | boolean)[]"`;
exports[`R_update(number)(boolean)(string_array) 1`] = `
"Argument of type 'string[]' is not assignable to parameter of type 'List<boolean>'.
Type 'string[]' is not assignable to type 'ArrayLike<boolean>'.
Index signatures are incompatible.
Type 'string' is not assignable to type 'boolean'."
`;
exports[`R_update(number, boolean) 1`] = `"<U>(list: U[] | ArrayLike<U>) => (boolean | U)[]"`;
exports[`R_update(number)(string)(string_array) 1`] = `"string[]"`;
exports[`R_update(number, boolean, string_array) 1`] = `"(string | boolean)[]"`;
exports[`R_update(number, boolean) 1`] = `"(list: boolean[] | ArrayLike<boolean>) => boolean[]"`;
exports[`R_update(number, boolean, string_array) 1`] = `
"Argument of type 'string[]' is not assignable to parameter of type 'List<boolean>'.
Type 'string[]' is not assignable to type 'ArrayLike<boolean>'."
`;
exports[`R_update(number, string, string_array) 1`] = `"string[]"`;
13 changes: 10 additions & 3 deletions tests/adjust.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {Morphism} from '../ramda/dist/src/$types';
import * as R_adjust from '../ramda/dist/src/adjust';

declare const string_to_string: Morphism<string, string>;
declare const string_to_number: Morphism<string, number>;
declare const string_array: string[];
declare const number: number;

// @dts-jest:pass
// @dts-jest:fail
R_adjust(string_to_number)(number, string_array);
// @dts-jest:pass
// @dts-jest:fail
R_adjust(string_to_number, number)(string_array);
// @dts-jest:pass
// @dts-jest:fail
R_adjust(string_to_number, number, string_array);
// @dts-jest:pass
R_adjust(string_to_string)(number, string_array);
// @dts-jest:pass
R_adjust(string_to_string, number)(string_array);
// @dts-jest:pass
R_adjust(string_to_string, number, string_array);
9 changes: 7 additions & 2 deletions tests/append.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as R_append from '../ramda/dist/src/append';

declare const string: string;
declare const number: number;
declare const number_array: number[];

// @dts-jest:pass
// @dts-jest:fail
R_append(string)(number_array);
// @dts-jest:pass
// @dts-jest:fail
R_append(string, number_array);
// @dts-jest:pass
R_append(number)(number_array);
// @dts-jest:pass
R_append(number, number_array);
12 changes: 10 additions & 2 deletions tests/insert.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import * as R_insert from '../ramda/dist/src/insert';

declare const object: object;
declare const object_array: object[];
declare const string: string;
declare const number: number;

// @dts-jest:pass
R_insert(number, string);
// @dts-jest:pass
// @dts-jest:fail
R_insert(number, string, object_array);
// @dts-jest:pass
// @dts-jest:fail
R_insert(number)(string)(object_array);

// @dts-jest:pass
R_insert(number, object);
// @dts-jest:pass
R_insert(number, object, object_array);
// @dts-jest:pass
R_insert(number)(object)(object_array);
8 changes: 6 additions & 2 deletions tests/insertAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ declare const number: number;

// @dts-jest:pass
R_insertAll(number, string_array);
// @dts-jest:pass
// @dts-jest:fail
R_insertAll(number, string_array, object_array);
// @dts-jest:pass
// @dts-jest:fail
R_insertAll(number)(string_array)(object_array);
// @dts-jest:pass
R_insertAll(number, string_array, string_array);
// @dts-jest:pass
R_insertAll(number)(string_array)(string_array);
Loading

0 comments on commit 12988ac

Please sign in to comment.