Skip to content

fix(fetchium): Fix declaration emit and rest subpath for downstream consumers - #1

Merged
jimmy-phantom merged 2 commits into
Signalium:mainfrom
jimmy-phantom:fetchium/export-typedef-symbol
Apr 7, 2026
Merged

fix(fetchium): Fix declaration emit and rest subpath for downstream consumers#1
jimmy-phantom merged 2 commits into
Signalium:mainfrom
jimmy-phantom:fetchium/export-typedef-symbol

Conversation

@jimmy-phantom

@jimmy-phantom jimmy-phantom commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix TS4029 declaration emit errors for downstream packages that compile with declaration: true. Replaced the unique symbol brand on TypeDef<T> with a string literal brand (__fetchiumTypeDef). TypeScript's declaration emitter cannot reference unique symbol across package boundaries (microsoft/TypeScript#56107), causing "cannot be named" errors whenever a combinator like t.optional() is used in an exported class.
  • Add rest subpath to Vite build so that fetchium/rest produces runtime JS bundles. The package.json exports declared ./rest but no JS was being built for it.

Changes

  1. packages/fetchium/src/types.ts — Replace unique symbol brand with string brand
  2. packages/fetchium/src/typeDefs.ts — Cast defineObject assignment to fix Record<string, TypeDef> constraint mismatch caused by string brand
  3. packages/fetchium/vite.config.ts — Add rest/index entry point

Verification

  • All 1124 unit tests pass
  • npm run build succeeds, producing rest/index.js for all output variants
  • @phantom/fetchium-client compiles with declaration: true producing zero errors (was 367 TS4029 errors before)
  • Wallet repo successfully consumes the built fetchium-client

Trade-off

String brands are slightly weaker than unique symbol (another library could theoretically define a type with __fetchiumTypeDef), but no real-world collisions have been reported for any library using this pattern (Drizzle ORM, ArkType, fp-ts, TypeScript compiler itself all use string brands). The unique symbol approach is fundamentally incompatible with TypeScript's declaration emitter for inferred types across package boundaries.

🤖 Generated with Claude Code

Export `TypeDefSymbol` from types.ts so downstream consumers can emit
.d.ts files without TS4029 errors when using TypeDef<T> in public type
positions, such as when extending Entity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jimmy-phantom
jimmy-phantom force-pushed the fetchium/export-typedef-symbol branch from 7fb6458 to 4c8c2db Compare April 6, 2026 17:05
Replace unique symbol brand with string brand to fix TS4029 errors
during declaration emit in downstream packages. TypeScript's declaration
emitter cannot reference unique symbols across package boundaries
(microsoft/TypeScript#56107), causing "cannot be named" errors for any
consumer compiling with declaration: true.

Also add the rest subpath entry to the Vite build config so that
fetchium/rest produces runtime JS bundles at the paths declared in
package.json exports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jimmy-phantom jimmy-phantom changed the title fix(fetchium): Export TypeDefSymbol for declaration emit fix(fetchium): Fix declaration emit and rest subpath for downstream consumers Apr 6, 2026
@jimmy-phantom
jimmy-phantom requested a review from pzuraq April 6, 2026 23:39
@jimmy-phantom
jimmy-phantom merged commit 610f77f into Signalium:main Apr 7, 2026
1 check passed
@jimmy-phantom
jimmy-phantom deleted the fetchium/export-typedef-symbol branch April 7, 2026 16:49
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.

2 participants