refactor(sdk): replace TypeScript enums with const objects for strip-types compatibility#8084
Conversation
…types compatibility Convert all 13 TypeScript enums to the `const object + type alias` pattern to support Node's built-in TypeScript strip-types feature, which does not support enums.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
ds300
left a comment
There was a problem hiding this comment.
there's a few very minor backcompat issues here that could be easily worked around, which i'd prefer us to do. but no biggie either way.
Co-authored-by: David Sheldrick <[email protected]>
…conversions Adds `declare namespace` type aliases for `MigrationFailureReason` and `PORTRAIT_BREAKPOINT` so that consumers using enum members in type position (e.g. `MigrationFailureReason.IncompatibleSubtype` as a type) continue to work after the enum-to-const-object refactor. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@claude fix |
|
Claude finished @steveruizok's task in 2m 59s —— View job Backward compat fix for
|
Add explicit @public annotations for MigrationFailureReason, its type alias, and namespace in migrate.ts while removing the long JSDoc block. Update the API report to reflect the symbol as public (undocumented). These changes standardize visibility annotations and simplify the documentation comment.
Add explicit `as ArrayBuffer` type assertions in worker template functions to satisfy TypeScript typings. The changes are limited to templates/image-pipeline/worker/providers/types.ts and templates/image-pipeline/worker/routes/generate.ts and do not alter runtime behavior; they prevent type errors when accessing ArrayBuffer properties.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
image-pipeline-template | e2cc538 | Commit Preview URL Branch Preview URL |
Feb 25 2026, 06:41 PM |
Add 12 new entries from PRs merged since v4.4.0: - Featured: click-through on transparent image pixels (#7942) - API: enum-to-const-object refactor (#8084) - Improvements: SVG sanitizer (#7896), save-on-blur (#8037) - Bug fixes: cross-origin download (#8090), zero-size draw (#8067), rich text toolbar cleanup (#8050), zoom threshold (#8040), selection foreground fallback (#8011), sticky note SVG shadow (#7934), arrow frame clamping (#7932), zero pressure draw (#5693)
Update `next.mdx` release notes to cover all SDK-relevant PRs merged to main since v4.4.0. Highlights: - Display values system (#8121) with breaking changes and migration guide - Click-through on transparent image pixels (#7942) - `Editor.resizeToBounds()` (#8120) - SVG sanitization (#7896) - TypeScript enum-to-const refactoring (#8084) - 14 bug fixes and 4 improvements ### Change type - [x] `other` ### Test plan 1. Verify the release notes render correctly on the docs site ### Release notes - Update next release notes with changes since v4.4.0. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: documentation-only changes updating release notes content and date, with no runtime/code behavior impact. > > **Overview** > Updates `apps/docs/content/releases/next.mdx` for the upcoming release by refreshing the date and replacing the brief blurb with expanded release notes. > > Documents new SDK surface area (`Geometry2d.ignoreHit`, `Editor.resizeToBounds`, `sanitizeSvg`), highlights click-through on transparent image pixels, and adds a list of recent improvements and bug fixes (paste parenting, link/alt-text persistence, SVG sanitization behavior, circular-dependency cleanup, and several crash/export/sync fixes). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5f7dc0a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
In order to publish the v4.5.0 release notes and record the v4.4.1 patch, this PR archives release notes and resets `next.mdx` for the next cycle. **v4.5.0.mdx** (new file): - Archived from `next.mdx` with full frontmatter, keywords, and GitHub release link - Featured sections: click-through on transparent image pixels (#7942), breaking `EmbedShapeUtil.configure()` change (#8034) - API changes: `Editor.getResizeScaleFactor()` (#8042), `TLImageAsset.pixelRatio` (#8163), `sanitizeSvg` (#7896), `experimental__onDropOnCanvas` (#7911), enum-to-const refactoring (#8084) - 6 improvements and 20 bug fixes from production **v4.4.0.mdx:** - Add v4.4.1 patch release section with tooltip positioning fix (#8171) - Add v4.4.1 to keywords **next.mdx:** - Reset with `last_version: v4.5.0` and empty content ### Change type - [x] `other` ### Code changes | Section | LOC change | | ------------- | ------------- | | Documentation | +128 / -107 |
In order to publish the v4.5.0 release notes and record the v4.4.1 patch, this PR archives release notes and resets `next.mdx` for the next cycle. **v4.5.0.mdx** (new file): - Archived from `next.mdx` with full frontmatter, keywords, and GitHub release link - Featured sections: click-through on transparent image pixels (#7942), breaking `EmbedShapeUtil.configure()` change (#8034) - API changes: `Editor.getResizeScaleFactor()` (#8042), `TLImageAsset.pixelRatio` (#8163), `sanitizeSvg` (#7896), `experimental__onDropOnCanvas` (#7911), enum-to-const refactoring (#8084) - 6 improvements and 20 bug fixes from production **v4.4.0.mdx:** - Add v4.4.1 patch release section with tooltip positioning fix (#8171) - Add v4.4.1 to keywords **next.mdx:** - Reset with `last_version: v4.5.0` and empty content ### Change type - [x] `other` ### Code changes | Section | LOC change | | ------------- | ------------- | | Documentation | +128 / -107 |
Closes #8083
In order to support Node's built-in TypeScript strip-types feature (which does not support enums), this PR converts all 13 TypeScript enums in the repo to the
const object + type aliaspattern.Changes
Public API (
@public):MigrationFailureReasoninpackages/store/src/lib/migrate.tsPORTRAIT_BREAKPOINTinpackages/tldraw/src/lib/ui/constants.tsInternal (SDK packages):
ArrowHandlesinpackages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsxHistoryRecorderStateinpackages/editor/src/lib/editor/managers/HistoryManager/HistoryManager.tsInternal (V1 migration compat,
@internal):TLV1ShapeType,TLV1ColorStyle,TLV1SizeStyle,TLV1DashStyle,TLV1AlignStyle,TLV1FontStyle,TLV1Decoration,TLV1AssetTypeinpackages/tldraw/src/lib/utils/tldr/buildFromV1Document.tsDocs app:
ArticleStatus,APIGroupinapps/docs/types/content-types.tsEnum members used in type position (e.g.
type: TLV1ShapeType.Drawin discriminated unions) have been updated to usetypeof(e.g.type: typeof TLV1ShapeType.Draw).Change type
improvementTest plan
The const object pattern produces identical runtime values and the same usage patterns as enums. All value-position usages (
MigrationFailureReason.MigrationError,PORTRAIT_BREAKPOINT.MOBILE, etc.) work unchanged. Type-position usages have been updated to usetypeof.Release notes
constobject + type alias pattern for compatibility with Node's built-in TypeScript support (strip-types).API changes
MigrationFailureReasonchanged fromenumtoconstobject with type alias (runtime-compatible, same values)PORTRAIT_BREAKPOINTchanged fromenumtoconstobject with type alias (runtime-compatible, same values)Note
Medium Risk
Moderate risk because it changes exported runtime symbols from
enumobjects to plain const objects, which can break consumers relying on enum-specific runtime behavior (e.g. reverse mappings) despite identical values.Overview
Refactors the codebase to eliminate TypeScript
enums in favor ofas constobjects plus union type aliases, improving compatibility with Node’sstrip-typestype-stripping.This includes public API surface changes for
@tldraw/store(MigrationFailureReason) and@tldraw/tldraw(PORTRAIT_BREAKPOINT), with generated API reports updated accordingly anddeclare namespaceshims added where needed for backward-compat type usage.Internal enums in the editor, tldraw arrow util, V1 document migration types, and docs content types are similarly converted, and enum-member type positions are updated to
typeof SomeConst.Member. Separately, the image-pipeline worker adds explicitArrayBuffercasts forbytes.bufferreturn/usage to satisfy typing.Written by Cursor Bugbot for commit 92edbe7. This will update automatically on new commits. Configure here.