You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
Some of the JS Fetch API is not implemented in Cloudflare Workers. One example of this is Body.blob() on a Request object, which is implemented in the JS Fetch API, but calling this function in a Cloudflare Worker will result in an error:
Failed to execute 'blob' on 'Body': the method is not implemented.
However, when using the Request type provided by the @cloudflare/worker-types repo, using Body.blob does not cause a type error and instead appears to be implemented:
Inspecting the types in this repo, it seems that the definition of Request is purely additive (adding the cf property) and does nothing to prohibit unimplemented properties:
Before discovering the official types repo for Cloudflare Workers, I implemented TypeScript types for my Workers from scratch. In order to make the types for Cloudflare's Fetch API omit properties from the JS Fetch API, I defined custom types prefixed with Cf, for example:
Auto-Generated Types
Types are now automatically generated with releases by parsing the runtime's source code, and merging in overrides/docs defined in this repository (for generics, overloads, comments, etc).
webworker no longer needs to (and shouldn't) be included in tsconfig lib.
The final merged AST that's used to render the TypeScript types, workers.json, is also included in the repository. This could be used to generate bindings for other languages that compile to WebAssembly. Rust output is coming soon.
Closes: #55, #75, #76, #81, #84, #96, #97, #100, #101, #102, #105, #106, #107, #108
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The Issue
Some of the JS Fetch API is not implemented in Cloudflare Workers. One example of this is
Body.blob()
on aRequest
object, which is implemented in the JS Fetch API, but calling this function in a Cloudflare Worker will result in an error:The Cloudflare Workers reference appears to agree (by omission) that
Body.blob
is not implemented:https://developers.cloudflare.com/workers/reference/apis/request/
However, when using the
![Screen Shot 2020-07-21 at 2 57 17 PM](https://user-images.githubusercontent.com/728164/88111330-95485300-cb62-11ea-943e-2af0f42e9886.png)
Request
type provided by the@cloudflare/worker-types
repo, usingBody.blob
does not cause a type error and instead appears to be implemented:Inspecting the types in this repo, it seems that the definition of
Request
is purely additive (adding thecf
property) and does nothing to prohibit unimplemented properties:A Possible Solution
Before discovering the official types repo for Cloudflare Workers, I implemented TypeScript types for my Workers from scratch. In order to make the types for Cloudflare's Fetch API omit properties from the JS Fetch API, I defined custom types prefixed with
Cf
, for example:By generating a custom type that inherits nothing from the official Fetch API types, unimplemented properties like
Body.blob
can be omitted.The text was updated successfully, but these errors were encountered: