Skip to content

Commit 3e3b0f6

Browse files
author
tankaiwen
committed
fix: the recursive types error
1 parent 9453c23 commit 3e3b0f6

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

demo/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Count extends Ayanami<State> {
3232
count: 0,
3333
}
3434

35+
otherProps: string = ''
36+
3537
constructor(private readonly tips: Tips) {
3638
super()
3739
}
@@ -41,6 +43,11 @@ class Count extends Ayanami<State> {
4143
return { count: state.count + count }
4244
}
4345

46+
@Reducer()
47+
addOne(state: State): State {
48+
return { count: state.count + 1 }
49+
}
50+
4451
@Reducer()
4552
reset(): State {
4653
return { count: 0 }

src/core/types.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,29 @@ type UnpackPayload<F, S> = UnpackEffectPayload<F, S> extends never
9494
: UnpackReducerPayload<F, S>
9595
: UnpackEffectPayload<F, S>
9696

97-
type PayloadMethodKeys<M, S> = {
98-
[key in keyof M]: UnpackPayload<M[key], S> extends never ? never : key
99-
}[keyof M]
97+
type PayloadMethodKeySet<M, S, SS extends keyof M> = {
98+
[key in SS]: M[key] extends
99+
| (() => Observable<EffectAction>)
100+
| ((payload$: Observable<any>) => Observable<EffectAction>)
101+
| ((payload$: Observable<any>, state$: Observable<S>) => Observable<EffectAction>)
102+
? key
103+
: M[key] extends (() => S) | ((state: S) => S) | ((state: S, payload: any) => S)
104+
? key
105+
: M[key] extends ((state: Draft<S>) => void) | ((state: Draft<S>, payload: any) => void)
106+
? key
107+
: M[key] extends Observable<any>
108+
? key
109+
: never
110+
}[SS]
100111

101112
export type ActionMethodOfAyanami<M extends Ayanami<S>, S> = Pick<
102-
{
103-
[key in keyof M]: UnpackPayload<M[key], S> extends never
104-
? never
105-
: ActionMethod<UnpackPayload<M[key], S>>
106-
},
107-
Exclude<PayloadMethodKeys<M, S>, keyof Ayanami<S>>
113+
{ [key in keyof M]: ActionMethod<UnpackPayload<M[key], S>> },
114+
PayloadMethodKeySet<M, S, Exclude<keyof M, keyof Ayanami<S>>>
108115
>
109116

110117
export type ActionOfAyanami<M extends Ayanami<S>, S> = Pick<
111-
{
112-
[key in keyof M]: UnpackPayload<M[key], S> extends never
113-
? never
114-
: ActionMethod<UnpackPayload<M[key], S>, EffectAction>
115-
},
116-
Exclude<PayloadMethodKeys<M, S>, keyof Ayanami<S>>
118+
{ [key in keyof M]: ActionMethod<UnpackPayload<M[key], S>, EffectAction> },
119+
PayloadMethodKeySet<M, S, Exclude<keyof M, keyof Ayanami<S>>>
117120
>
118121

119122
export interface ObjectOf<T> {

0 commit comments

Comments
 (0)