Repository navigation
Description
Existing documentation URL(s)
What changes are you suggesting?
Update the documented Worker so the four TypeScript blocks compile together in a strict TypeScript project using Cloudflare's published Workers types. The two JSON handlers need input types before destructuring, and the SVG helpers need return types that agree with the data they return and the attachment binding accepts.
Additional information
Summary
The example presents one Worker with handlers for PDF, inline-image and uploaded-file attachments. Assembling its four TypeScript blocks produces six compiler errors before any of the routes can be tested.
Steps to reproduce
- Install the compiler and Workers types listed under Runtime or environment in a scratch directory.
- Copy the contents of the four TypeScript blocks into
attachments.tsin page order, starting with the Worker entry point. Leave the Wrangler configuration out. The check below joins the blocks without inserting extra blank lines between them. - Run the compiler command. It checks types only and sends no email.
npx tsc --strict --target ES2022 --lib es2022 --types @cloudflare/workers-types --noEmit attachments.tsExpected behavior
The Worker compiles with strict checking. The invoice and report handlers can read their JSON fields, and the two SVG helpers return the buffer type they declare.
Actual behavior
The compiler exits 1. The invoice and report handlers destructure properties from unknown. The two SVG helpers return ArrayBufferLike where they declare ArrayBuffer.
attachments.ts(29,10): error TS2339: Property 'customerEmail' does not exist on type 'unknown'.
attachments.ts(29,25): error TS2339: Property 'invoiceData' does not exist on type 'unknown'.
attachments.ts(146,10): error TS2339: Property 'recipientEmail' does not exist on type 'unknown'.
attachments.ts(146,26): error TS2339: Property 'reportData' does not exist on type 'unknown'.
attachments.ts(219,2): error TS2322: Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
attachments.ts(232,2): error TS2322: Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
The published Markdown export and the corresponding production source yield identical TypeScript blocks and diagnostics. A local control with explicit JSON output types and an owned buffer in each SVG helper exits 0 under the same compiler command.
Evidence
- Expected source: Workers TypeScript guidance describes the published Workers types and their stable package entry point. The attachment example presents a typed entry point and the three functions it calls.
- Failure source:
src/content/docs/email-service/examples/email-sending/email-attachments.mdx. The JSON calls are insendInvoiceWithPDFandsendReportWithImages. The buffer returns are ingenerateChartImageandgetCompanyLogo. - Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
Restoration check
Assemble the corrected blocks in page order and run the same strict check. The Worker entry point and all three attachment handlers should compile.
Runtime or environment
Published Cloudflare Developer Docs and production revision cd5bf82ac1d0d34fe13997eb15c6727b498cd926. The local check used TypeScript 7.0.2, @cloudflare/workers-types 5.20261202.1 and Node.js 26.13.1.
Triage assessment
- Impact level: P2
- Assessment status: supported
- Impact basis: Readers integrating the documented attachments Worker into a strict TypeScript project encounter six errors before testing its send paths.
- Workaround status: unverified
- Workaround basis: The local diagnostic control type-checked after changing the example code. No configuration-only workaround that preserves the example's behavior was verified.
References
- fix(email-service): invoice attachment example produces a damaged PDF #35753 — The completed repair addressed generated PDF bytes. The current example still fails at the TypeScript compiler.
- fix(email-service): local sending docs incorrectly say binary attachments require deployment #35525 — This report covers binary attachment serialization under the local simulator. The compiler failures occur before either attachment generation or local sending.
Activity
[Email Service] Fix SMTP response note, Python smtplib example, and a…