workers-types icon indicating copy to clipboard operation
workers-types copied to clipboard

Use with Deno

Open tv42 opened this issue 4 years ago • 2 comments

deno bundle is a great future-forward way of bundling Typescript into an ESM, and compared to webpack et al, is a great developer experience for writing Cloudflare Workers.

However, so far I've always resorted to creating my own types for the Cloudflare-specific APIs. It would be great to reuse the work here with Deno, but that hits a few barriers:

  • types are not exported https://github.com/cloudflare/workers-types/issues/195
  • many of the defined types conflict with Deno's definitions, and if you start stripping away the defaults (https://deno.land/[email protected]/typescript/types#using-triple-slash-directives), you end up with weirder conflicts like whether EventListenerOrEventListenerObject is generic or not.

It would be great to have a tested & upstreamed way of importing these types into a Deno program.

tv42 avatar Feb 24 '22 17:02 tv42

Community efforts:

  • https://github.com/ericselin/worker-types (just the types, duplicating the effort here)
  • https://github.com/skymethod/denoflare (this one seems like an alternate implementation of wrangler/miniflare?)

tv42 avatar Feb 24 '22 17:02 tv42

There's also my library samuelcolvin/edge-mock which tries to provide implementations of the types defined in workers-types for use in testing. It's targeted at node, but much of it could probably be used on deno.

samuelcolvin avatar Mar 09 '22 20:03 samuelcolvin

Hey! 👋 Thanks for reporting this, we're actively thinking about ways of fixing this in the next major version of workers-types using the new type generation system. 👍

mrbbot avatar Oct 21 '22 13:10 mrbbot

Hey! 👋 As of @cloudflare/workers-types@4, you can selectively import type { ... } from "@cloudflare/workers-types". Hopefully this is sufficient for your use case. There are no plans at the moment for officially supported Deno integration.

mrbbot avatar Jan 19 '23 17:01 mrbbot