oak
oak copied to clipboard
Bug: RouterContext does not extend Application State
Hello,
I have defined an application state type and a separate request state type. If I use the Context type like this Context<RequestContext, AppContext>
everything looks good within my handler. But my issue starts when I try to use this handler in a router I get a typescript error that looks like this.
The types of 'app.state' are incompatible between these types.
Type 'Record<string, any>' is not assignable to type 'AppContext'.deno-ts(2345)
I have been looking through the code trying to figure out where this Record<string, any>
is coming from and from digging around I can see that RouteContext
is not specifying the second generic to Context
export interface RouterContext<
R extends string,
P extends RouteParams<R> = RouteParams<R>,
// deno-lint-ignore no-explicit-any
S extends State = Record<string, any>,
> extends Context<S>
I think this should be something like
export interface RouterContext<
R extends string,
P extends RouteParams<R> = RouteParams<R>,
// deno-lint-ignore no-explicit-any
S extends State = Record<string, any>,
AS extends State = Record<string, any>
> extends Context<S, AS>
to fix this issue. I'm not a Typescript expert though so happy to be pointed to the right direction if I'm incorrect in my assumption here. Happy to attempt to make the PR as well if this is a valid solution.