Skip to content

fix(codegen-ts): emit type-only Drizzle symbols with import type (verbatimModuleSyntax) (#165)#166

Merged
dmealing merged 1 commit into
mainfrom
fix/165-verbatim-module-syntax-type-imports
Jul 4, 2026
Merged

fix(codegen-ts): emit type-only Drizzle symbols with import type (verbatimModuleSyntax) (#165)#166
dmealing merged 1 commit into
mainfrom
fix/165-verbatim-module-syntax-type-imports

Conversation

@dmealing

@dmealing dmealing commented Jul 4, 2026

Copy link
Copy Markdown
Member

Fixes #165.

Problem

The default entityFile() output imports Drizzle type-only symbols as value imports — InferSelectModel / InferInsertModel (drizzle-orm) and AnyPgColumn / AnySQLiteColumn (*-core, 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, so a generated DAO fails tsc -b with 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 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, e.g. import { relations, type InferInsertModel } from "drizzle-orm"). Three one-line changes in inferred-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 / renderInferredTypes primitives.

Verification

  • New real-tsc compile guard with verbatimModuleSyntax ON, over an entity with a self-referential FK (so AnyPgColumn is exercised). A negative control (revert the fix) confirms it fails with TS1484 for all three symbols; with the fix it's zero diagnostics.
  • Golden snapshots updated — the only change is value→type imports (diff inspected).
  • Full codegen-ts suite green (909), typecheck clean.

TS-only (codegen output); no metamodel or cross-port impact.

🤖 Generated with Claude Code

…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
@dmealing
dmealing merged commit 3f776aa into main Jul 4, 2026
1 check passed
@dmealing
dmealing deleted the fix/165-verbatim-module-syntax-type-imports branch July 4, 2026 16:11
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.

codegen-ts entityFile emits Drizzle type-only symbols as value imports (fails tsc under verbatimModuleSyntax)

1 participant