cloudflare / workers-types

TypeScript type definitions for authoring Cloudflare Workers.
BSD 3-Clause "New" or "Revised" License
359 stars 89 forks source link

HtmlRewriter ElementHandler methods can only accept strings (not general Content) #312

Closed petebacondarwin closed 1 year ago

petebacondarwin commented 1 year ago

Many of the methods on the ElementHandler interface (e.g. append()) accept a Content parameter, which is currently typed as type Content = string | ReadableStream | Response. But it turns out that these methods only accept a string.

See https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/#methods and https://github.com/cloudflare/workers-types/blob/c0de39ad801dec05dca608ef654888612fd42945/index.d.ts#L445-L463 and https://github.com/cloudflare/workers-types/blob/c0de39ad801dec05dca608ef654888612fd42945/index.d.ts#L136

It is not implemented in LOL_HTML at all... https://github.com/cloudflare/lol-html/blob/2b2fb691f191f8f0f5147be1955c56232089e133/c-api/src/element.rs#L159 But at least should throw a useful error in workerd https://github.com/cloudflare/workerd/blob/main/src/workerd/api/html-rewriter.c%2B%2B#L683-L687

mrbbot commented 1 year ago

content is now typed as a string in @cloudflare/workers-types@4 so I think we should be able to close this. 👍