Skip to content

Commit 2755a04

Browse files
committed
revert(type): revert the ExtContext type support
1 parent cbc7956 commit 2755a04

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

__test__/Model/extContext.multi.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ describe('useStore', () => {
1010
let testActions: any
1111
let extState: any
1212
let extActions: any
13+
// @ts-ignore
1314
const Test = Model(ExtCounter, { name: 'test' })
15+
// @ts-ignore
1416
const Ext = Model(ExtCounter, { name: 'ext' })
1517
const { useStore } = Model({ Test, Ext })
1618
renderHook(() => {

src/index.d.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface Global {
3838
type ClassSetter = React.Dispatch<any> | undefined
3939

4040
// Very Sad, Promise<ProduceFunc<S>> can not work with Partial<S> | ProduceFunc<S>
41-
type Action<S = {}, P = any, ActionKeys = {}, ExtContext = {}> = (
41+
type Action<S = {}, P = any, ActionKeys = {}, ExtContext extends {} = {}> = (
4242
params: P,
4343
context: {
4444
state: S
@@ -55,7 +55,7 @@ type Action<S = {}, P = any, ActionKeys = {}, ExtContext = {}> = (
5555
type ProduceFunc<S> = (state: S) => void
5656

5757
// v3.0 Actions
58-
type Actions<S = {}, ActionKeys = {}, ExtContext = {}> = {
58+
type Actions<S = {}, ActionKeys = {}, ExtContext extends object = {}> = {
5959
[P in keyof ActionKeys]: Action<S, ActionKeys[P], ActionKeys, ExtContext>
6060
}
6161

@@ -94,13 +94,13 @@ type Context<S = {}> = (InnerContext<S>) & {
9494

9595
type Middleware<S = {}> = (C: Context<S>, M: Middleware<S>[]) => void
9696

97-
interface Models<State = any, ActionKeys = any> {
97+
interface Models<State = any, ActionKeys = any, ExtContext extends {} = {}> {
9898
[name: string]:
99-
| ModelType<State, ActionKeys>
100-
| API<ModelType<State, ActionKeys>>
99+
| ModelType<State, ActionKeys, ExtContext>
100+
| API<ModelType<State, ActionKeys, {}>>
101101
}
102102

103-
interface API<MT extends ModelType = any> {
103+
interface API<MT extends ModelType = ModelType<any, any, {}>> {
104104
__id: string
105105
useStore: (
106106
depActions?: Array<keyof MT['actions']>
@@ -162,7 +162,11 @@ interface APIs<M extends Models> {
162162
}
163163

164164
// v3.0
165-
type ModelType<InitStateType = any, ActionKeys = any, ExtContext = {}> = {
165+
type ModelType<
166+
InitStateType = any,
167+
ActionKeys = any,
168+
ExtContext extends {} = {}
169+
> = {
166170
actions: {
167171
[P in keyof ActionKeys]: Action<
168172
InitStateType,

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const isAPI = (input: any): input is API => {
1818
return (input as API).useStore !== undefined
1919
}
2020

21-
function Model<E, MT extends ModelType<any, any, E>>(
21+
function Model<E, Ctx extends {}, MT extends ModelType<any, any, {}>>(
2222
models: MT,
2323
// initialState represent extContext here
2424
initialState?: E

0 commit comments

Comments
 (0)