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

The request type inferred from ExportedHandler is any instead of Request. #2474

Open
tavoyne opened this issue Aug 3, 2024 · 9 comments
Open
Assignees
Labels
needs reproduction types Related to @cloudflare/workers-types

Comments

@tavoyne
Copy link

tavoyne commented Aug 3, 2024

image

@tavoyne tavoyne added the types Related to @cloudflare/workers-types label Aug 3, 2024
@tavoyne tavoyne changed the title The request type inferred from ExportedHandler is any instead of `Request. The request type inferred from ExportedHandler is any instead of Request. Aug 3, 2024
@petebacondarwin
Copy link
Contributor

Can you provide a reproduction (perhaps git repository) that we can use to diagnose this problem?

@asimpletune
Copy link

I am having the same issue right now. For me @cloudflare/[email protected] + [email protected] were definitely working, and I see this issue appearing with the at latest @cloudflare/[email protected] + [email protected], although possible earlier.

@asimpletune
Copy link

I did sort of a bisect of wrangler versions x @cloudflare/worker-types. The last version of wrangler that I found compatible with the last working version of worker-types was 3.36.0 x 4.20240208.0.

In other words, npm install [email protected] @cloudflare/[email protected] --save-dev is the latest version of the two working together, for me at least.

One caveat though is that I was testing this against my particular use case, which was with PagesFunction<Env>, not ExportedHandler.

@asimpletune
Copy link

I could be wrong but it looks like the issue was introduced about 6 months ago, here https://github.com/cloudflare/workerd/blame/a47804f8bbcd06904bb9eae91e0e6c3ffdc7f6d6/types/defines/pages.d.ts#L4.

It looks like Request doesn't have generics, although they're being used here.

@penalosa
Copy link
Collaborator

The Request defined in @cloudflare/workers-types does have generics, so that should work, I think.

@asimpletune Would you be able to provide a reproduction repo that demonstrates the issue?

@asimpletune
Copy link

Hi! Id love to but I can't for a few weeks. But if you create a new project with the versions I listed above you will see the same results.

Although, the version I cited is when the issue was first introduced, so it should be present with wrangler 3.72.0 and its sibling worker types file.

Otherwise I can create a new issue when I'm available again, since the issue I brought up is only similar to the OP but not guaranteed to be the same.

@yunsii
Copy link

yunsii commented Sep 7, 2024

@Cherry
Copy link
Contributor

Cherry commented Sep 8, 2024

There's a couple of issues with your setup @yunsii:

  "pnpm": {
    "overrides": {
      "@types/node": "20.8.3"
    }
  },
  • Then you're also loading DOM types in your lib config in your tsconfig, which also has its own version of Request. Remove this.

After this, the request type works fine in your example.

If you have a need for DOM types, I'd recommend a different tsconfig.json for your worker, and your frontend.


For others experiencing this issue, I'd double check those two things - your lib in your tsconfig.json, and that @types/node is pinned to an old version, as per the previously linked issue.

@yunsii
Copy link

yunsii commented Sep 8, 2024

@Cherry Thanks for your detailed explanation, it is a interesting issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction types Related to @cloudflare/workers-types
Projects
Status: Untriaged
Development

No branches or pull requests

7 participants