Skip to content

Commit 67019c5

Browse files
committed
Fix KeyedEventHandler wrongly identifies keyed handlers
Before that commit, KeyedEventHandler< (ctx) => Promise<void> > would type check, while the desired outcome that it would type check to 'never'. Now we check explicitly for the following shapes and type check them to 'never': ``` 1. () => Promise<void> 2. (ctx) => Promise<void> ```
1 parent e18db25 commit 67019c5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/types/router.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export type KeyedHandler<F> = F extends (ctx: RpcContext) => Promise<any>
7171
: never;
7272

7373
export type KeyedRouterOpts<U> = {
74-
[K in keyof U]: U[K] extends KeyedHandler<any> | KeyedEventHandler<U[K]>
74+
[K in keyof U]: U[K] extends KeyedHandler<U[K]> | KeyedEventHandler<U[K]>
7575
? U[K]
7676
: never;
7777
};
@@ -93,10 +93,11 @@ export const keyedRouter = <M>(opts: KeyedRouterOpts<M>): KeyedRouter<M> => {
9393

9494
// ----------- event handlers ----------------------------------------------
9595

96-
export type KeyedEventHandler<U> = U extends (
97-
ctx: RpcContext,
98-
event: Event
99-
) => Promise<void>
96+
export type KeyedEventHandler<U> = U extends () => Promise<void>
97+
? never
98+
: U extends (ctx: RpcContext) => Promise<void>
99+
? never
100+
: U extends (ctx: RpcContext, event: Event) => Promise<void>
100101
? U
101102
: never;
102103

0 commit comments

Comments
 (0)