Fix packaged t.infer declarations and add post-pack TypeScript smoke test#19
Open
cnpap wants to merge 1 commit intosurrealdb:mainfrom
Open
Fix packaged t.infer declarations and add post-pack TypeScript smoke test#19cnpap wants to merge 1 commit intosurrealdb:mainfrom
cnpap wants to merge 1 commit intosurrealdb:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a packaging regression in
surqlize@0.1.0where the published TypeScript declarations fort.inferbecome syntactically invalid after declaration bundling.The change keeps the public API unchanged:
t.infer<typeof query>still works the same for consumersIt 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.inferas a directly declared public type alias:This is valid in source, but after declaration bundling the published
dist/index.d.tswas emitted into an invalid form:At that point
infer<T>is parsed as invalid syntax, so any normal TypeScript consumer that importssurqlizefails during declaration parsing before regular type-checking.In other words:
What Changed
1. Keep
t.inferpublic API, change only how it is exported internallyInstead of directly declaring a public type named
infer, this PR defines an internal type alias and re-exports it asinfer.Before:
After:
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.mtsIt exercises the packaged tarball as a real consumer would:
orm,table, andtfromsurqlizet.infer<typeof query>(typeof user)["type"]3. Run the new smoke test in CI after
npm packThe smoke workflow now:
npm packtypescripttsc --noEmitagainst the smoke fixtureThis 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:
That is not actually the supported table-row typing API today, because
table()returnsTableSchema, andt.inferis defined forAbstractType | Workable, not forTableSchema.The table row type is already exposed on
TableSchema["type"], so the README now uses:This is a documentation correction to match the current library behavior.
Why This Is Safe
t.inferconsumer syntax changedValidation
Locally verified with:
bun run buildbun run type-checkPackaged-consumer verification:
npm packnpx tsc --noEmit --skipLibCheck --module nodenext --moduleResolution nodenext type-check.mtsnode node-esm.mjsnode node-cjs.cjsThe 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:
t.infer<typeof ...>