/
groupBy-spec.ts
49 lines (40 loc) · 1.23 KB
/
groupBy-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
import {groupBy} from 'rambda'
import {groupBy as groupByRamda, prop} from 'ramda'
interface Thing {
name: string,
position: string,
}
interface Output {
left: Thing[],
right: Thing[],
}
const things = [
{name: 'one', position: 'left'},
{name: 'two', position: 'left'},
{name: 'three', position: 'right'},
{name: 'four', position: 'right'},
]
describe('R.groupBy', () => {
it('happy', () => {
const groupByFn = (x: string) => String(x.length)
const list = ['foo', 'barr']
const result = groupBy(groupByFn, list)
result // $ExpectType { [index: string]: string[]; }
const curriedResult = groupBy(groupByFn)(list)
curriedResult // $ExpectType { [index: string]: string[]; }
})
it('with one explicit types', () => {
const groupByPosition = groupBy<Thing>(prop('position'))
// $ExpectError
groupByRamda(prop('position'))
const result = groupByPosition(things)
result // $ExpectType { [index: string]: Thing[]; }
result[9] // $ExpectType Thing[]
result.foo // $ExpectType Thing[]
})
it('with two explicit types', () => {
const groupByPosition = groupBy<Thing, Output>(prop('position'))
const result = groupByPosition(things)
result // $ExpectType Output
})
})