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