Skip to content

Commit 67056a0

Browse files
fix(overmind-react): fix typing
1 parent c2fae89 commit 67056a0

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

packages/node_modules/overmind-react/src/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('React', () => {
167167
const FooComponent = () => {
168168
const state = useState()
169169

170-
return <h1>{state.foo}</h1>
170+
return <h1>{(state as any).foo}</h1>
171171
}
172172

173173
expect(() => {

packages/node_modules/overmind-react/src/index.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import {
22
ENVIRONMENT,
33
EventType,
4+
IConfiguration,
45
IContext,
56
IReaction,
67
MODE_SSR,
78
Overmind,
89
OvermindMock,
910
} from 'overmind'
1011
import * as react from 'react'
11-
import {
12-
unstable_cancelCallback,
13-
unstable_getCurrentPriorityLevel,
14-
unstable_scheduleCallback,
15-
} from 'scheduler'
1612

1713
const IS_PRODUCTION = ENVIRONMENT === 'production'
1814
const IS_TEST = ENVIRONMENT === 'test'
@@ -23,7 +19,7 @@ const isNode =
2319
process.title.includes('node')
2420

2521
export type IReactComponent<P = any> =
26-
| react.StatelessComponent<P>
22+
| react.FunctionComponent<P>
2723
| react.ComponentClass<P>
2824
| react.ClassicComponentClass<P>
2925

@@ -83,7 +79,7 @@ const useCurrentComponent = () => {
8379
: {}
8480
}
8581

86-
const useState = <Context extends IContext<any>>(
82+
const useState = <Context extends IContext<IConfiguration>>(
8783
cb?: (state: Context['state']) => any
8884
): Context['state'] => {
8985
const overmind = react.useContext(context) as Overmind<any>
@@ -187,7 +183,9 @@ const useState = <Context extends IContext<any>>(
187183
return state
188184
}
189185

190-
const useActions = <Context extends IContext<any>>(): Context['actions'] => {
186+
const useActions = <
187+
Context extends IContext<IConfiguration>
188+
>(): Context['actions'] => {
191189
const overmind = react.useContext(context) as Overmind<any>
192190

193191
if (!(overmind as any).mode) {
@@ -197,7 +195,9 @@ const useActions = <Context extends IContext<any>>(): Context['actions'] => {
197195
return overmind.actions
198196
}
199197

200-
const useEffects = <Context extends IContext<any>>(): Context['effects'] => {
198+
const useEffects = <
199+
Context extends IContext<IConfiguration>
200+
>(): Context['effects'] => {
201201
const overmind = react.useContext(context) as Overmind<any>
202202

203203
if (!(overmind as any).mode) {
@@ -207,7 +207,9 @@ const useEffects = <Context extends IContext<any>>(): Context['effects'] => {
207207
return overmind.effects
208208
}
209209

210-
const useReaction = <Context extends IContext<any>>(): IReaction<Context> => {
210+
const useReaction = <Context extends IContext<IConfiguration>>(): IReaction<
211+
Context
212+
> => {
211213
const overmind = react.useContext(context) as Overmind<any>
212214

213215
if (!(overmind as any).mode) {
@@ -217,29 +219,29 @@ const useReaction = <Context extends IContext<any>>(): IReaction<Context> => {
217219
return overmind.reaction as any
218220
}
219221

220-
export interface StateHook<Context extends IContext<any>> {
222+
export interface StateHook<Context extends IContext<IConfiguration>> {
221223
(): Context['state']
222224
<T>(cb?: (state: Context['state']) => T): T
223225
}
224226

225-
export const createStateHook: <Context extends IContext<any>>() => StateHook<
226-
Context
227-
> = () => useState
227+
export const createStateHook: <
228+
Context extends IContext<IConfiguration>
229+
>() => StateHook<Context> = () => useState
228230

229231
export const createActionsHook: <
230-
Context extends IContext<any>
232+
Context extends IContext<IConfiguration>
231233
>() => () => Context['actions'] = () => {
232234
return useActions as any
233235
}
234236

235237
export const createEffectsHook: <
236-
Context extends IContext<any>
238+
Context extends IContext<IConfiguration>
237239
>() => () => Context['effects'] = () => {
238240
return useEffects as any
239241
}
240242

241243
export const createReactionHook: <
242-
Context extends IContext<any>
244+
Context extends IContext<IConfiguration>
243245
>() => () => IReaction<Context> = () => {
244246
return useReaction as any
245247
}

0 commit comments

Comments
 (0)