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: After using npm create cloudflare most examples do not work with TypeScript types #6328

Closed
davidbarratt opened this issue Jul 24, 2024 · 1 comment · Fixed by #6333
Labels
bug Something that isn't working

Comments

@davidbarratt
Copy link

davidbarratt commented Jul 24, 2024

Which Cloudflare product(s) does this pertain to?

C3 (npm create cloudflare)

What version(s) of the tool(s) are you using?

2.22.2 [C3]

What version of Node are you using?

20.15.1

What operating system and version are you using?

Ubuntu through WSL

Describe the Bug

Observed behavior

Please describe.

Expected behavior

Please describe.

Steps to reproduce

  1. Run npm cloudflare create with the "Hello World" Worker and with TypeScript
  2. From the fetch handler, return the response from the global fetch()
    return fetch(request);
  3. You should now get a type error

I tried an alternative syntax and it also fails with a different error:

const response = await fetch(request);
return new Response(response.body, response);

Please provide a link to a minimal reproduction

https://github.com/davidbarratt/worker-types/blob/b75bd22eab7d8ab9bfb65362360d5015ad351aa4/src/index.ts#L15-L17

You can see the error if you go to the src/index.ts file here (and wait for TypeScript to load):
https://stackblitz.com/~/github.com/davidbarratt/worker-types

Please provide any relevant error logs

Type 'Response' is missing the following properties from type 'Response': webSocket, cf, bytests(2739)

or with the alternative format (creating a new Response):

Argument of type 'ReadableStream<any> | null' is not assignable to parameter of type 'BodyInit | null | undefined'.
  Type 'ReadableStream<any>' is not assignable to type 'BodyInit | null | undefined'.
    Type 'ReadableStream<any>' is not assignable to type 'ReadableStream<Uint8Array>'.
      The types returned by 'getReader(...)' are incompatible between these types.
        Property 'readAtLeast' is missing in type 'ReadableStreamDefaultReader<any>' but required in type 'ReadableStreamBYOBReader'.ts(2345)
@davidbarratt davidbarratt added the bug Something that isn't working label Jul 24, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jul 24, 2024
@Cherry
Copy link
Contributor

Cherry commented Jul 24, 2024

This looks very much like cloudflare/workerd#1298 to me.

And if I throw the following as described in that issue, into your package.json and reinstall, the errors do sure enough disappear:

   "overrides": {
        "@types/node": "20.8.3"
    }

If it's happening with a fresh npm create cloudflare project now though, that's concerning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants