-
Notifications
You must be signed in to change notification settings - Fork 1
/
basics.js
116 lines (105 loc) · 2.12 KB
/
basics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
jest.autoMockOff();
const defineInlineTest = require('../../testUtils.js').defineInlineTest;
const transform = require('../generic-bounds.js');
transform.parser = 'flow';
describe('generic bounds in functions', () => {
defineInlineTest(
transform,
{},
`
function foo<X: string>(x: X): X {
return x
}
`,
`
function foo<X extends string>(x: X): X {
return x
}
`
);
defineInlineTest(
transform,
{},
`
function foo<X: string | number | Foo>(x: X): X {
return x
}
`,
`
function foo<X extends string | number | Foo>(x: X): X {
return x
}
`
);
defineInlineTest(
transform,
{},
`
function foo<X: number, Y: string | Bar>(x: X): X {
return x
}
`,
`
function foo<X extends number, Y extends string | Bar>(x: X): X {
return x
}
`
);
});
describe('generic bounds in interface definitions', () => {
defineInlineTest(
transform,
{},
`
interface Item<X: string, Y: number | Foo>(x: X): X {
return x
}
`,
`
interface Item<X extends string, Y extends number | Foo>(x: X): X {
return x
}
`
);
});
describe('generic bounds in class definitions', () => {
defineInlineTest(
transform,
{},
`
class Item<X: string, Y: number | Foo | Bar>(x: X) {
// ...
}
`,
`
class Item<X extends string, Y extends number | Foo | Bar>(x: X) {
// ...
}
`
);
});
// TODO: investigate inference of generic arguments
// https://flow.org/en/docs/types/generics/#toc-supplying-type-arguments-to-callables
/*
// @flow
class GenericClass<T, U, V>{}
const c = new GenericClass<_, number, _>()
*/
// TODO: investigate defaults in parameterized generics
// https://flow.org/en/docs/types/generics/#toc-adding-defaults-to-parameterized-generics
/*
// @flow
type Item<T: number = 1> = {
prop: T,
};
let foo: Item<> = { prop: 1 };
let bar: Item<2> = { prop: 2 };
*/
// TODO: investigate variance sigils in generics
// https://flow.org/en/docs/types/generics/#toc-variance-sigils
/*
// @flow
type GenericBox<+T> = T;
var x: GenericBox<number> = 3;
(x: GenericBox<number| string>);
*/