Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: RouterContext does not extend Application State #520

Open
Teddy-Schmitz opened this issue May 9, 2022 · 0 comments
Open

Bug: RouterContext does not extend Application State #520

Teddy-Schmitz opened this issue May 9, 2022 · 0 comments

Comments

@Teddy-Schmitz
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant