Skip to content

[T3 Connect] TypeScript codegen: type DbConnection.db with a merged interface for Babel/Expo - #6013

Draft
bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-codegen-db-interface
Draft

bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-codegen-db-interface

Conversation

@bradleyshep

@bradleyshep bradleyshep commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of the work to move T3 Code's T3 Connect relay onto SpacetimeDB.

Description of Changes

Generated TypeScript bindings narrowed db with declare db: DbView;. Babel rejects declare class fields unless allowDeclareFields is set, and babel-preset-expo doesn't set it. So React Native and Expo apps couldn't bundle generated bindings for any module with snake_case table accessor aliases.

Codegen now declares the narrowed type on an interface merged into the class. Like before, it's type-only. The snapshots are updated.

One linter difference: Biome's default noUnsafeDeclarationMerging rule reports the merged interface (ESLint and oxlint don't, and the generated header already disables ESLint). Projects that lint generated bindings with Biome would need to exclude them.

Split out of #6006.

Companion: clockworklabs/spacetime-web#1395 updates the website's generated control database bindings. The "Check spacetime-web bindings" job compares against spacetime-web main for public PRs, so it fails here until that merges; the two should land together.

API and ABI breaking changes

None. Generated code has the same type and the same runtime output.

Rollback safety impact

n/a

Expected complexity level and risk

Testing

  • pnpm build and pnpm test in crates/bindings-typescript (322 passing)
  • Generated bindings before and after this change transpile to identical JavaScript in tsc, esbuild, swc and Babel, with useDefineForClassFields on and off
  • babel-preset-expo rejects the old bindings ("The 'declare' modifier is only allowed when…") and accepts the new ones
  • An Expo app bundles bindings generated by this codegen for a module with snake_case accessors
  • cargo test -p spacetimedb-codegen

@bradleyshep
bradleyshep force-pushed the bradley/ts-codegen-db-interface branch from 4bec9b6 to 884f4d8 Compare September 30, 2026 17:38
@bradleyshep bradleyshep changed the title TypeScript codegen: type DbConnection.db with a merged interface for Babel/Expo [T3 Connect] TypeScript codegen: type DbConnection.db with a merged interface for Babel/Expo Sep 30, 2026
Generated TypeScript bindings narrowed `db` with `declare db: DbView;`.
Babel rejects `declare` class fields unless `allowDeclareFields` is set,
and babel-preset-expo does not set it, so React Native and Expo apps
could not bundle generated bindings for any module with snake_case table
accessor aliases.

Declare the narrowed type on an interface merged into the class instead.
It is type-only like before and emits nothing in any transpiler. Updated
the codegen snapshot and the checked-in bindings to match.
@bradleyshep
bradleyshep force-pushed the bradley/ts-codegen-db-interface branch from 884f4d8 to 080dc12 Compare October 1, 2026 17:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant