deno.land / x / rambda@v9.1.1 / source / indexBy-spec.ts

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
37
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; } })})
rambda

Version Info

Tagged at
2 months ago