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

composeAsync-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
import {composeAsync, delay, pipeAsync} from 'rambda'
describe('R.composeAsync', () => { it('no need to pass type argument on second function', () => { const result = composeAsync( async x => { x // $ExpectType number[] return Promise.resolve(String(x[0])) }, (x: number) => Promise.resolve([x]) )(1)
result // $ExpectType Promise<string> }) it('pass type of function input', async() => { const fn = composeAsync( // Notice the type parameter here. Because of the order of the functions, // TypeScript won't infer the type of `x` from later functions, but using // a type parameter we can leave it generic and properly compute the // result type at the end. <T>(x: T) => { x // $ExpectType T return Promise.resolve([x]) }, x => { x // $ExpectType number return new Promise<string>(resolve => { resolve(x.toString()) }) }, async(x: 4) => { x // $ExpectType 4 await delay(100) return x + 1 } )
const result1 = await fn(4) const result2 = await fn(Promise.resolve(4))
result1 // $ExpectType string[] result2 // $ExpectType string[] })})
describe('R.pipeAsync', () => { it('happy', () => { const result = pipeAsync( (x: number) => Promise.resolve([x]), async x => { x // $ExpectType number[] return Promise.resolve(String(x[0])) } )(1)
result // $ExpectType Promise<string> })})
rambda

Version Info

Tagged at
2 months ago