Created
May 6, 2024 23:46
-
-
Save fzn0x/cedc9ff2e6c99e1c4a20f4a93eb98a19 to your computer and use it in GitHub Desktop.
wip: dynamic handler types to enforce return value in Hono handlers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handler type when `next` is NOT provided and a response is expected | |
export type HandlerWithoutNext<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = | |
(c: Context<E, P, I>) => R; | |
// Handler type when `next` is provided | |
export type HandlerWithNext<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = | |
(c: Context<E, P, I>, next: Next) => void; | |
// Union type to combine both handler types | |
export type Handler<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = HandlerWithoutNext<E, P, I, R> | HandlerWithNext<E, P, I, R>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment