|
1 | 1 | import { Action, AnyAction } from './actions' |
2 | 2 | import { Reducer } from './reducers' |
3 | 3 |
|
4 | | -/** |
5 | | - * Extend the state |
6 | | - * |
7 | | - * This is used by store enhancers and store creators to extend state. |
8 | | - * If there is no state extension, it just returns the state, as is, otherwise |
9 | | - * it returns the state joined with its extension. |
10 | | - * |
11 | | - * Reference for future devs: |
12 | | - * https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919 |
13 | | - */ |
14 | | -export type ExtendState<State, Extension> = [Extension] extends [never] |
15 | | - ? State |
16 | | - : State & Extension |
17 | | - |
18 | 4 | /** |
19 | 5 | * Internal "virtual" symbol used to make the `CombinedState` type unique. |
20 | 6 | */ |
@@ -125,7 +111,7 @@ export type Observer<T> = { |
125 | 111 | export interface Store< |
126 | 112 | S = any, |
127 | 113 | A extends Action = AnyAction, |
128 | | - StateExt = never |
| 114 | + StateExt = {} |
129 | 115 | > { |
130 | 116 | /** |
131 | 117 | * Dispatches an action. It is the only way to trigger a state change. |
@@ -160,7 +146,7 @@ export interface Store< |
160 | 146 | * |
161 | 147 | * @returns The current state tree of your application. |
162 | 148 | */ |
163 | | - getState(): ExtendState<S, StateExt> |
| 149 | + getState(): S & StateExt |
164 | 150 |
|
165 | 151 | /** |
166 | 152 | * Adds a change listener. It will be called any time an action is |
@@ -205,7 +191,7 @@ export interface Store< |
205 | 191 | * For more information, see the observable proposal: |
206 | 192 | * https://github.com/tc39/proposal-observable |
207 | 193 | */ |
208 | | - [Symbol.observable](): Observable<ExtendState<S, StateExt>> |
| 194 | + [Symbol.observable](): Observable<S & StateExt> |
209 | 195 | } |
210 | 196 |
|
211 | 197 | /** |
@@ -256,10 +242,10 @@ export interface StoreCreator { |
256 | 242 | * @template Ext Store extension that is mixed into the Store type. |
257 | 243 | * @template StateExt State extension that is mixed into the state type. |
258 | 244 | */ |
259 | | -export type StoreEnhancer<Ext = {}, StateExt = never> = ( |
| 245 | +export type StoreEnhancer<Ext = {}, StateExt = {}> = ( |
260 | 246 | next: StoreEnhancerStoreCreator |
261 | 247 | ) => StoreEnhancerStoreCreator<Ext, StateExt> |
262 | | -export type StoreEnhancerStoreCreator<Ext = {}, StateExt = never> = < |
| 248 | +export type StoreEnhancerStoreCreator<Ext = {}, StateExt = {}> = < |
263 | 249 | S = any, |
264 | 250 | A extends Action = AnyAction |
265 | 251 | >( |
|
0 commit comments