Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61223f2

Browse filesBrowse files
committed
Add tests
1 parent 8a76939 commit 61223f2
Copy full SHA for 61223f2

4 files changed

+839Lines changed: 839 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+107Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//// [genericContextualTypes1.ts]
2+
type Box<T> = { value: T };
3+
4+
declare function wrap<A, B>(f: (a: A) => B): (a: A) => B;
5+
6+
declare function compose<A, B, C>(f: (a: A) => B, g: (b: B) => C): (a: A) => C;
7+
8+
declare function list<T>(a: T): T[];
9+
10+
declare function unlist<T>(a: T[]): T;
11+
12+
declare function box<V>(x: V): Box<V>;
13+
14+
declare function unbox<W>(x: Box<W>): W;
15+
16+
declare function map<T, U>(a: T[], f: (x: T) => U): U[];
17+
18+
declare function identity<T>(x: T): T;
19+
20+
declare function zip<A, B>(a: A, b: B): [A, B];
21+
22+
declare function flip<X, Y, Z>(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z;
23+
24+
const f00: <A>(x: A) => A[] = list;
25+
const f01: <A>(x: A) => A[] = x => [x];
26+
const f02: <A>(x: A) => A[] = wrap(list);
27+
const f03: <A>(x: A) => A[] = wrap(x => [x]);
28+
29+
const f10: <T>(x: T) => Box<T[]> = compose(a => list(a), b => box(b));
30+
const f11: <T>(x: T) => Box<T[]> = compose(list, box);
31+
const f12: <T>(x: Box<T[]>) => T = compose(a => unbox(a), b => unlist(b));
32+
const f13: <T>(x: Box<T[]>) => T = compose(unbox, unlist);
33+
34+
const arrayMap = <T, U>(f: (x: T) => U) => (a: T[]) => a.map(f);
35+
const arrayFilter = <T>(f: (x: T) => boolean) => (a: T[]) => a.filter(f);
36+
37+
const f20: (a: string[]) => number[] = arrayMap(x => x.length);
38+
const f21: <A>(a: A[]) => A[][] = arrayMap(x => [x]);
39+
const f22: <A>(a: A[]) => A[] = arrayMap(identity);
40+
const f23: <A>(a: A[]) => Box<A>[] = arrayMap(value => ({ value }));
41+
42+
const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10);
43+
const f31: <T extends Box<number>>(a: T[]) => T[] = arrayFilter(x => x.value > 10);
44+
45+
const f40: <A, B>(b: B, a: A) => [A, B] = flip(zip);
46+
47+
// Repro from #16293
48+
49+
type fn = <A>(a: A) => A;
50+
const fn: fn = a => a;
51+
52+
53+
//// [genericContextualTypes1.js]
54+
"use strict";
55+
var f00 = list;
56+
var f01 = function (x) { return [x]; };
57+
var f02 = wrap(list);
58+
var f03 = wrap(function (x) { return [x]; });
59+
var f10 = compose(function (a) { return list(a); }, function (b) { return box(b); });
60+
var f11 = compose(list, box);
61+
var f12 = compose(function (a) { return unbox(a); }, function (b) { return unlist(b); });
62+
var f13 = compose(unbox, unlist);
63+
var arrayMap = function (f) { return function (a) { return a.map(f); }; };
64+
var arrayFilter = function (f) { return function (a) { return a.filter(f); }; };
65+
var f20 = arrayMap(function (x) { return x.length; });
66+
var f21 = arrayMap(function (x) { return [x]; });
67+
var f22 = arrayMap(identity);
68+
var f23 = arrayMap(function (value) { return ({ value: value }); });
69+
var f30 = arrayFilter(function (x) { return x.length > 10; });
70+
var f31 = arrayFilter(function (x) { return x.value > 10; });
71+
var f40 = flip(zip);
72+
var fn = function (a) { return a; };
73+
74+
75+
//// [genericContextualTypes1.d.ts]
76+
declare type Box<T> = {
77+
value: T;
78+
};
79+
declare function wrap<A, B>(f: (a: A) => B): (a: A) => B;
80+
declare function compose<A, B, C>(f: (a: A) => B, g: (b: B) => C): (a: A) => C;
81+
declare function list<T>(a: T): T[];
82+
declare function unlist<T>(a: T[]): T;
83+
declare function box<V>(x: V): Box<V>;
84+
declare function unbox<W>(x: Box<W>): W;
85+
declare function map<T, U>(a: T[], f: (x: T) => U): U[];
86+
declare function identity<T>(x: T): T;
87+
declare function zip<A, B>(a: A, b: B): [A, B];
88+
declare function flip<X, Y, Z>(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z;
89+
declare const f00: <A>(x: A) => A[];
90+
declare const f01: <A>(x: A) => A[];
91+
declare const f02: <A>(x: A) => A[];
92+
declare const f03: <A>(x: A) => A[];
93+
declare const f10: <T>(x: T) => Box<T[]>;
94+
declare const f11: <T>(x: T) => Box<T[]>;
95+
declare const f12: <T>(x: Box<T[]>) => T;
96+
declare const f13: <T>(x: Box<T[]>) => T;
97+
declare const arrayMap: <T, U>(f: (x: T) => U) => (a: T[]) => U[];
98+
declare const arrayFilter: <T>(f: (x: T) => boolean) => (a: T[]) => T[];
99+
declare const f20: (a: string[]) => number[];
100+
declare const f21: <A>(a: A[]) => A[][];
101+
declare const f22: <A>(a: A[]) => A[];
102+
declare const f23: <A>(a: A[]) => Box<A>[];
103+
declare const f30: (a: string[]) => string[];
104+
declare const f31: <T extends Box<number>>(a: T[]) => T[];
105+
declare const f40: <A, B>(b: B, a: A) => [A, B];
106+
declare type fn = <A>(a: A) => A;
107+
declare const fn: fn;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.