fix(codegen-ts): emit type-only Drizzle symbols with import type (verbatimModuleSyntax) (#165)#166
Merged
Conversation
…batimModuleSyntax) (#165) The default entityFile() output imported Drizzle's type-only symbols as VALUE imports: InferSelectModel / InferInsertModel (drizzle-orm) and AnyPgColumn / AnySQLiteColumn (the *-core package, used only as a .references() return-type annotation). Under `verbatimModuleSyntax: true` — a common default in modern Vite/TS app templates — tsc rejects each with TS1484 ("… is a type and must be imported using a type-only import"), so a generated DAO fails `tsc -b` with hundreds of errors even though it runs fine under a bundler. Mark the three symbols type-only via ts-poet's `t:` prefix (the idiom already used for FastifyInstance/Hono/TPH imports), so they emit as `import type` (or an inline `type` modifier when mixed with value imports from the same module). This fixes both the built-in generator and the ADR-0034 scaffold-and-own reference template, which delegates to the same renderDrizzleSchema / renderInferredTypes primitives. Adds a real-tsc compile guard with verbatimModuleSyntax ON over an entity with a self-referential FK (so AnyPgColumn is exercised); a negative control confirms it catches the TS1484 regression for all three symbols. Golden snapshots updated (the only change is value→type imports). TS-only; codegen output, no metamodel or cross-port impact. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ew1XfYSbEAezxjs9opynAe
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.
Fixes #165.
Problem
The default
entityFile()output imports Drizzle type-only symbols as value imports —InferSelectModel/InferInsertModel(drizzle-orm) andAnyPgColumn/AnySQLiteColumn(*-core, used only as a.references()return-type annotation). UnderverbatimModuleSyntax: true(a common default in modern Vite/TS app templates), tsc rejects each with TS1484, so a generated DAO failstsc -bwith hundreds of errors even though it runs fine under a bundler.Fix
Mark the three symbols type-only via ts-poet's
t:prefix — the idiom already used forFastifyInstance/Hono/TPH imports — so they emit asimport type(or an inlinetypemodifier when mixed with value imports from the same module, e.g.import { relations, type InferInsertModel } from "drizzle-orm"). Three one-line changes ininferred-types.ts+drizzle-schema.ts.This fixes both the built-in generator and the ADR-0034 scaffold-and-own reference template, which delegates to the same
renderDrizzleSchema/renderInferredTypesprimitives.Verification
tsccompile guard withverbatimModuleSyntaxON, over an entity with a self-referential FK (soAnyPgColumnis exercised). A negative control (revert the fix) confirms it fails with TS1484 for all three symbols; with the fix it's zero diagnostics.TS-only (codegen output); no metamodel or cross-port impact.
🤖 Generated with Claude Code