Skip to content

Commit 2b7df64

Browse files
committed
Prefer that
1 parent 9ac1852 commit 2b7df64

File tree

3 files changed

+7
-58
lines changed

3 files changed

+7
-58
lines changed

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export {
1919
Store,
2020
StoreCreator,
2121
StoreEnhancer,
22-
StoreEnhancerStoreCreator,
23-
ExtendState
22+
StoreEnhancerStoreCreator
2423
} from './types/store'
2524
// reducers
2625
export {

src/types/store.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import { Action, AnyAction } from './actions'
22
import { Reducer } from './reducers'
33

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-
184
/**
195
* Internal "virtual" symbol used to make the `CombinedState` type unique.
206
*/
@@ -125,7 +111,7 @@ export type Observer<T> = {
125111
export interface Store<
126112
S = any,
127113
A extends Action = AnyAction,
128-
StateExt = never
114+
StateExt = {}
129115
> {
130116
/**
131117
* Dispatches an action. It is the only way to trigger a state change.
@@ -160,7 +146,7 @@ export interface Store<
160146
*
161147
* @returns The current state tree of your application.
162148
*/
163-
getState(): ExtendState<S, StateExt>
149+
getState(): S & StateExt
164150

165151
/**
166152
* Adds a change listener. It will be called any time an action is
@@ -205,7 +191,7 @@ export interface Store<
205191
* For more information, see the observable proposal:
206192
* https://github.com/tc39/proposal-observable
207193
*/
208-
[Symbol.observable](): Observable<ExtendState<S, StateExt>>
194+
[Symbol.observable](): Observable<S & StateExt>
209195
}
210196

211197
/**
@@ -256,10 +242,10 @@ export interface StoreCreator {
256242
* @template Ext Store extension that is mixed into the Store type.
257243
* @template StateExt State extension that is mixed into the state type.
258244
*/
259-
export type StoreEnhancer<Ext = {}, StateExt = never> = (
245+
export type StoreEnhancer<Ext = {}, StateExt = {}> = (
260246
next: StoreEnhancerStoreCreator
261247
) => StoreEnhancerStoreCreator<Ext, StateExt>
262-
export type StoreEnhancerStoreCreator<Ext = {}, StateExt = never> = <
248+
export type StoreEnhancerStoreCreator<Ext = {}, StateExt = {}> = <
263249
S = any,
264250
A extends Action = AnyAction
265251
>(

test/typescript/store.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
Action,
66
StoreEnhancer,
77
Unsubscribe,
8-
Observer,
9-
ExtendState
8+
Observer
109
} from '../..'
1110
import 'symbol-observable'
1211

@@ -18,41 +17,6 @@ type State = {
1817
}
1918
}
2019

21-
/* extended state */
22-
const noExtend: ExtendState<State, never> = {
23-
a: 'a',
24-
b: {
25-
c: 'c',
26-
d: 'd'
27-
}
28-
}
29-
// typings:expect-error
30-
const noExtendError: ExtendState<State, never> = {
31-
a: 'a',
32-
b: {
33-
c: 'c',
34-
d: 'd'
35-
},
36-
e: 'oops'
37-
}
38-
39-
const yesExtend: ExtendState<State, { yes: 'we can' }> = {
40-
a: 'a',
41-
b: {
42-
c: 'c',
43-
d: 'd'
44-
},
45-
yes: 'we can'
46-
}
47-
// typings:expect-error
48-
const yesExtendError: ExtendState<State, { yes: 'we can' }> = {
49-
a: 'a',
50-
b: {
51-
c: 'c',
52-
d: 'd'
53-
}
54-
}
55-
5620
interface DerivedAction extends Action {
5721
type: 'a'
5822
b: 'b'

0 commit comments

Comments
 (0)