1
- import { getDefaultMiddleware } from '@reduxjs/toolkit'
1
+ import { getDefaultMiddleware , configureStore } from '@reduxjs/toolkit'
2
2
import type { Middleware } from 'redux'
3
- import type { DispatchForMiddlewares } from '@internal/tsHelpers'
4
3
5
4
declare const expectType : < T > ( t : T ) => T
6
5
@@ -12,103 +11,108 @@ declare const middleware2: Middleware<{
12
11
( _ : number ) : string
13
12
} >
14
13
15
- declare const getDispatch : < M extends Array < Middleware > > (
16
- m : M
17
- ) => DispatchForMiddlewares < M >
18
-
19
14
type ThunkReturn = Promise < 'thunk' >
20
15
declare const thunkCreator : ( ) => ( ) => ThunkReturn
21
16
22
17
{
23
- const defaultMiddleware = getDefaultMiddleware ( )
24
-
25
18
// prepend single element
26
19
{
27
- const concatenated = defaultMiddleware . prepend ( middleware1 )
28
- const dispatch = getDispatch ( concatenated )
29
- expectType < number > ( dispatch ( 'foo' ) )
30
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
20
+ const store = configureStore ( {
21
+ reducer : ( ) => 0 ,
22
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware1 ) ,
23
+ } )
24
+ expectType < number > ( store . dispatch ( 'foo' ) )
25
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
31
26
32
27
// @ts -expect-error
33
- expectType < string > ( dispatch ( 'foo' ) )
28
+ expectType < string > ( store . dispatch ( 'foo' ) )
34
29
}
35
30
36
- // prepepend multiple (rest)
31
+ // prepend multiple (rest)
37
32
{
38
- const concatenated = defaultMiddleware . prepend ( middleware1 , middleware2 )
39
- const dispatch = getDispatch ( concatenated )
40
- expectType < number > ( dispatch ( 'foo' ) )
41
- expectType < string > ( dispatch ( 5 ) )
42
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
33
+ const store = configureStore ( {
34
+ reducer : ( ) => 0 ,
35
+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware1 , middleware2 ) ,
36
+ } )
37
+ expectType < number > ( store . dispatch ( 'foo' ) )
38
+ expectType < string > ( store . dispatch ( 5 ) )
39
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
43
40
44
41
// @ts -expect-error
45
- expectType < string > ( dispatch ( 'foo' ) )
42
+ expectType < string > ( store . dispatch ( 'foo' ) )
46
43
}
47
44
48
45
// prepend multiple (array notation)
49
46
{
50
- const concatenated = defaultMiddleware . prepend ( [
51
- middleware1 ,
52
- middleware2 ,
53
- ] as const )
54
- const dispatch = getDispatch ( concatenated )
55
- expectType < number > ( dispatch ( 'foo' ) )
56
- expectType < string > ( dispatch ( 5 ) )
57
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
47
+ const store = configureStore ( {
48
+ reducer : ( ) => 0 ,
49
+ middleware : ( gDM ) => gDM ( ) . prepend ( [ middleware1 , middleware2 ] as const ) ,
50
+ } )
51
+
52
+ expectType < number > ( store . dispatch ( 'foo' ) )
53
+ expectType < string > ( store . dispatch ( 5 ) )
54
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
58
55
59
56
// @ts -expect-error
60
- expectType < string > ( dispatch ( 'foo' ) )
57
+ expectType < string > ( store . dispatch ( 'foo' ) )
61
58
}
62
59
63
60
// concat single element
64
61
{
65
- const concatenated = defaultMiddleware . concat ( middleware1 )
66
- const dispatch = getDispatch ( concatenated )
67
- expectType < number > ( dispatch ( 'foo' ) )
68
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
62
+ const store = configureStore ( {
63
+ reducer : ( ) => 0 ,
64
+ middleware : ( gDM ) => gDM ( ) . concat ( middleware1 ) ,
65
+ } )
66
+
67
+ expectType < number > ( store . dispatch ( 'foo' ) )
68
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
69
69
70
70
// @ts -expect-error
71
- expectType < string > ( dispatch ( 'foo' ) )
71
+ expectType < string > ( store . dispatch ( 'foo' ) )
72
72
}
73
73
74
- // prepepend multiple (rest)
74
+ // prepend multiple (rest)
75
75
{
76
- const concatenated = defaultMiddleware . concat ( middleware1 , middleware2 )
77
- const dispatch = getDispatch ( concatenated )
78
- expectType < number > ( dispatch ( 'foo' ) )
79
- expectType < string > ( dispatch ( 5 ) )
80
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
76
+ const store = configureStore ( {
77
+ reducer : ( ) => 0 ,
78
+ middleware : ( gDM ) => gDM ( ) . concat ( middleware1 , middleware2 ) ,
79
+ } )
80
+
81
+ expectType < number > ( store . dispatch ( 'foo' ) )
82
+ expectType < string > ( store . dispatch ( 5 ) )
83
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
81
84
82
85
// @ts -expect-error
83
- expectType < string > ( dispatch ( 'foo' ) )
86
+ expectType < string > ( store . dispatch ( 'foo' ) )
84
87
}
85
88
86
89
// concat multiple (array notation)
87
90
{
88
- const concatenated = defaultMiddleware . concat ( [
89
- middleware1 ,
90
- middleware2 ,
91
- ] as const )
92
- const dispatch = getDispatch ( concatenated )
93
- expectType < number > ( dispatch ( 'foo' ) )
94
- expectType < string > ( dispatch ( 5 ) )
95
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
91
+ const store = configureStore ( {
92
+ reducer : ( ) => 0 ,
93
+ middleware : ( gDM ) => gDM ( ) . concat ( [ middleware1 , middleware2 ] as const ) ,
94
+ } )
95
+
96
+ expectType < number > ( store . dispatch ( 'foo' ) )
97
+ expectType < string > ( store . dispatch ( 5 ) )
98
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
96
99
97
100
// @ts -expect-error
98
- expectType < string > ( dispatch ( 'foo' ) )
101
+ expectType < string > ( store . dispatch ( 'foo' ) )
99
102
}
100
103
101
104
// concat and prepend
102
105
{
103
- const concatenated = defaultMiddleware
104
- . concat ( middleware1 )
105
- . prepend ( middleware2 )
106
- const dispatch = getDispatch ( concatenated )
107
- expectType < number > ( dispatch ( 'foo' ) )
108
- expectType < string > ( dispatch ( 5 ) )
109
- expectType < ThunkReturn > ( dispatch ( thunkCreator ( ) ) )
106
+ const store = configureStore ( {
107
+ reducer : ( ) => 0 ,
108
+ middleware : ( gDM ) => gDM ( ) . concat ( middleware1 ) . prepend ( middleware2 ) ,
109
+ } )
110
+
111
+ expectType < number > ( store . dispatch ( 'foo' ) )
112
+ expectType < string > ( store . dispatch ( 5 ) )
113
+ expectType < ThunkReturn > ( store . dispatch ( thunkCreator ( ) ) )
110
114
111
115
// @ts -expect-error
112
- expectType < string > ( dispatch ( 'foo' ) )
116
+ expectType < string > ( store . dispatch ( 'foo' ) )
113
117
}
114
118
}
0 commit comments