Next.js Discord

Discord Forum

Overload imported modules correctly

Unanswered
Texas leafcutting ant posted this in #help-forum
Open in Discord
Texas leafcutting antOP
I am using next, and I find the the type of NextApiResponse to be problematic in that it does not require a generic in order to correctly type the json method.

I am trying to overload the module so as to require a generic:

declare module 'next' {
  import {Send} from 'express'
  import {NextApiRequest} from 'next'

  export declare type NextApiResponse<T> = {
    json: Send<T>
  }
  export declare type NextApiRequest = NextApiRequest
}


I use it as such
res: NextApiResponse<{t: 1}>,

But I still see any as the inferred type of json.

1 Reply

Texas leafcutting antOP
I have noticed that something is giving the response type an additional generic I don't seem able to overload