/
map-spec.ts
79 lines (77 loc) · 2.1 KB
/
map-spec.ts
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
import {map} from 'rambda'
describe('R.map with arrays', () => {
it('iterable returns the same type as the input', () => {
const result = map<number>(
(x: number) => {
x // $ExpectType number
return x + 2
},
[1, 2, 3]
)
result // $ExpectType number[]
})
it('iterable returns the same type as the input - curried', () => {
const result = map<number>((x: number) => {
x // $ExpectType number
return x + 2
})([1, 2, 3])
result // $ExpectType number[]
})
it('iterable returns different type as the input', () => {
const result = map<number, string>(
(x: number) => {
x // $ExpectType number
return String(x)
},
[1, 2, 3]
)
result // $ExpectType string[]
})
})
describe('R.map with objects', () => {
it('iterable with all three arguments - curried', () => {
// It requires dummy third typing argument
// in order to identify compared to curry typings for arrays
// ============================================
const result = map<number, string, any>((a, b, c) => {
a // $ExpectType number
b // $ExpectType string
c // $ExpectType Dictionary<number>
return `${a}`
})({a: 1, b: 2})
result // $ExpectType Dictionary<string>
})
it('iterable with all three arguments', () => {
const result = map<number, string>(
(a, b, c) => {
a // $ExpectType number
b // $ExpectType string
c // $ExpectType Dictionary<number>
return `${a}`
},
{a: 1, b: 2}
)
result // $ExpectType Dictionary<string>
})
it('iterable with property argument', () => {
const result = map<number, string>(
(a, b) => {
a // $ExpectType number
b // $ExpectType string
return `${a}`
},
{a: 1, b: 2}
)
result // $ExpectType Dictionary<string>
})
it('iterable with no property argument', () => {
const result = map<number, string>(
a => {
a // $ExpectType number
return `${a}`
},
{a: 1, b: 2}
)
result // $ExpectType Dictionary<string>
})
})