Skip to content

Fix packaged t.infer declarations and add post-pack TypeScript smoke test#19

Open
cnpap wants to merge 1 commit intosurrealdb:mainfrom
cnpap:fix/infer-type
Open

Fix packaged t.infer declarations and add post-pack TypeScript smoke test#19
cnpap wants to merge 1 commit intosurrealdb:mainfrom
cnpap:fix/infer-type

Conversation

@cnpap
Copy link
Copy Markdown

@cnpap cnpap commented Mar 18, 2026

Summary

This fixes a packaging regression in surqlize@0.1.0 where the published TypeScript declarations for t.infer become syntactically invalid after declaration bundling.

The change keeps the public API unchanged:

  • t.infer<typeof query> still works the same for consumers

It also adds a post-pack TypeScript smoke test so we validate the packaged tarball, not only the source tree.

Root Cause

The source currently exposes t.infer as a directly declared public type alias:

export type infer<T extends AbstractType | Workable> = ...

This is valid in source, but after declaration bundling the published dist/index.d.ts was emitted into an invalid form:

type t_infer<T extends AbstractType | Workable> = infer<T>;

At that point infer<T> is parsed as invalid syntax, so any normal TypeScript consumer that imports surqlize fails during declaration parsing before regular type-checking.

In other words:

  • runtime usage is fine
  • source type-check is fine
  • published bundled declarations are broken

What Changed

1. Keep t.infer public API, change only how it is exported internally

Instead of directly declaring a public type named infer, this PR defines an internal type alias and re-exports it as infer.

Before:

export type infer<T extends AbstractType | Workable> = ...

After:

type InferType<T extends AbstractType | Workable> = ...
export type { InferType as infer };

This keeps the external API stable while preventing the declaration bundler from emitting the broken = infer<T> form.

2. Add a packaged TypeScript smoke test

This PR adds a new smoke fixture:

  • tests/smoke/type-check.mts

It exercises the packaged tarball as a real consumer would:

  • imports orm, table, and t from surqlize
  • builds a query
  • uses t.infer<typeof query>
  • verifies table row typing via (typeof user)["type"]

3. Run the new smoke test in CI after npm pack

The smoke workflow now:

  • builds the package
  • creates a tarball with npm pack
  • installs that tarball into an isolated directory
  • installs typescript
  • runs tsc --noEmit against the smoke fixture

This closes the gap where source checks passed but packaged declarations were never validated.

4. Correct the README table row type example

The README previously showed:

type User = t.infer<typeof userTable>;

That is not actually the supported table-row typing API today, because table() returns TableSchema, and t.infer is defined for AbstractType | Workable, not for TableSchema.

The table row type is already exposed on TableSchema["type"], so the README now uses:

type User = (typeof userTable)["type"];

This is a documentation correction to match the current library behavior.

Why This Is Safe

  • No runtime behavior changed
  • No query-builder behavior changed
  • No public t.infer consumer syntax changed
  • The fix is limited to declaration emission shape and CI coverage

Validation

Locally verified with:

  • bun run build
  • bun run type-check

Packaged-consumer verification:

  • npm pack
  • install tarball into an isolated temp project
  • npx tsc --noEmit --skipLibCheck --module nodenext --moduleResolution nodenext type-check.mts
  • node node-esm.mjs
  • node node-cjs.cjs

The packaged tarball now type-checks successfully and no longer emits the invalid type t_infer = infer<T> declaration form.

Reviewer Notes

The important behavior to review is the packaged declaration output, not only the source diff.

The key guarantee from this PR is:

  • users can keep writing t.infer<typeof ...>
  • published declarations remain parseable
  • CI now catches this class of regression before release

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