-
Notifications
You must be signed in to change notification settings - Fork 86
/
indexBy-spec.ts
36 lines (32 loc) · 1.03 KB
/
indexBy-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
import {indexBy} from 'rambda'
const list = [{a: {b: '1'}}, {a: {c: '2'}}, {a: {b: '3'}}]
describe('indexBy', () => {
it('happy', () => {
const result = indexBy(x => x.a.b, list)
const curriedResult = indexBy<any>(x => x.a.b)(list)
result.foo?.a.b // $ExpectType string | undefined
curriedResult // $ExpectType { [x: string]: any; }
})
it('with string', () => {
const result = indexBy('a.b', list)
const curriedResult = indexBy<any>('a.b')(list)
result.foo?.a.b // $ExpectType string | undefined
curriedResult // $ExpectType { [key: string]: any; }
})
it('with interface', () => {
interface Foo {
a: string,
}
const interfaceList = [{a: 'foo'}, {a: 'bar'}]
const result = indexBy<Foo>(x => {
x.a // $ExpectType string
return x.a
}, interfaceList)
const curriedResult = indexBy<Foo>(x => {
x.a // $ExpectType string
return x.a
})(interfaceList)
result // $ExpectType { [x: string]: Foo; }
curriedResult // $ExpectType { [x: string]: Foo; }
})
})