Skip to content

Conversation

@sayaad
Copy link

@sayaad sayaad commented May 24, 2025

Seperate type imports and class imports for typescript client bindings codegen

Description of Changes

Currently the code generation works fine following the typescript client setup tutorial in the documentation if you select Typescript+SWC as the variant in the vite template menu
image
However if you select typescript only, the bindings generated by spacetimedb will not be bundled correctly by vite. This is described in vite's documentation here:
image
The end result is a client side error of trying to import a type from a JS file:
image

This fix separates the type imports from the class imports in the generated typescript code, turning:

import {
  AlgebraicType,
  AlgebraicValue,
  BinaryReader,
  BinaryWriter,
  CallReducerFlags,
  ConnectionId,
  DbConnectionBuilder,
  DbConnectionImpl,
  DbContext,
  ErrorContextInterface,
  Event,
  EventContextInterface,
  Identity,
  ProductType,
  ProductTypeElement,
  ReducerEventContextInterface,
  SubscriptionBuilderImpl,
  SubscriptionEventContextInterface,
  SumType,
  SumTypeVariant,
  TableCache,
  TimeDuration,
  Timestamp,
  deepEqual,
} from "@clockworklabs/spacetimedb-sdk";

into

import {
  AlgebraicType,
  AlgebraicValue,
  BinaryReader,
  BinaryWriter,
  ConnectionId,
  DbConnectionBuilder,
  DbConnectionImpl,
  Identity,
  ProductType,
  ProductTypeElement,
  SubscriptionBuilderImpl,
  SumType,
  SumTypeVariant,
  TableCache,
  TimeDuration,
  Timestamp,
  deepEqual,
} from "@clockworklabs/spacetimedb-sdk";
import type {
  CallReducerFlags,
  DbContext,
  ErrorContextInterface,
  Event,
  EventContextInterface,
  ReducerEventContextInterface,
  SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";

solving the problem.

Relevant issues

#3024
#2661

API and ABI breaking changes

This is not a breaking change

Expected complexity level and risk

1

Testing

  • Repository compiles
  • Typescript codegen generates correct typescript code
  • Typescript code generated by typescript codegen works in the plain Typescript variant of vite.

@CLAassistant
Copy link

CLAassistant commented May 24, 2025

CLA assistant check
All committers have signed the CLA.

@sayaad
Copy link
Author

sayaad commented May 24, 2025

Closing: This was previously fixed by #2747

@sayaad sayaad closed this May 24, 2025
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