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

Correct type of request not recognized when using withCookies and withContent #19

Open
RicardoViteriR opened this issue Dec 4, 2021 · 3 comments

Comments

@RicardoViteriR
Copy link

I have the following function that I cannot get to recognize the request when using the withCookies and withContent middleware.

I tried using import { Request as IttyRequest} from 'itty-router' but I get Property 'content' does not exist on type 'Request'

export async function handleRefresh(req: any): Promise<Response> {
  const payload: RefreshTokenData = req.content ?? {};
}

Can someone tell me how I can get the right type?

@mkuchak
Copy link

mkuchak commented Apr 9, 2022

I ran into this problem today and solved it like this:

Create a path and a file to track custom types src/@types/itty-router/index.d.ts:

interface Request {
  content?: any;
  cookies?: any;
  params?: any;
}

Add this line in tsconfig.json:

 {
   "compilerOptions": {
     "typeRoots": ["./src/@types"],
   },
 }

For reference:
https://github.com/mkuchak/cloudflare-workers-template/blob/main/src/@types/itty-router/index.d.ts
https://github.com/mkuchak/cloudflare-workers-template/blob/main/tsconfig.json#L15

@RicardoViteriR
Copy link
Author

Hi @mkuchak, thanks for sharing. Do you know if this solution would extend or replace the Request interface?

@mkuchak
Copy link

mkuchak commented Apr 9, 2022

This extends the interface Request

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

2 participants