You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8626fc9
Browse filesBrowse the repository at this point in the historyBrowse files
fix(codegen-ts): emit JS array literal for isArray @default (TS2345) (#146)
A downstream adopter upgrading to 0.15.1 hit non-compiling Drizzle output for
an array field with a default, e.g. `field.string { isArray: true,
default: "{}" }`. The pg entity generator emitted
`text("conditions").array().notNull().default("{}")`, which fails `tsc` with
TS2345 — Drizzle's `.array().default(x)` wants `string[] | SQL`, not a string.
The same shape broke SQLite (`.$type<E[]>().default("{}")`).
Root cause: pre-0.15.0 an isArray string field mapped to jsonb, where
`.default("[]")` was valid. The 0.15.0 @dbColumnType slim-and-derive (ADR-0036)
made isArray emit a native text[] (`.array()`) column, but the default-emitter
still passed the raw @default string through.
Fix (codegen-ts only — the Java loader requires @default to be a string, so an
array default MUST be authored as "[]"/"{}"; it cannot be fixed in metadata):
parse the metadata default string for a scalar isArray field into a real JS
array literal via a new `{ kind: "arrayLiteral", elements }` DefaultExpr.
- "{}" / "[]" -> .default([])
- "{a,b}" / '["a","b"]' -> .default(["a", "b"]) (elements quoted per type)
- unsupported/ambiguous shape -> .default(sql`...`) so output ALWAYS
typechecks, never a bare string
Scalar/flat defaults and object/map-array storage are byte-identical.
Tests: shape assertions in column-mapper.test.ts plus a real-tsc compile guard
(array-default-compile.test.ts, mirroring projection/compile.test.ts) that
proves the generated entity typechecks with ZERO diagnostics on both dialects —
it reproduces the exact TS2345 without the fix.
Cross-port note: Java currently ignores array @default (emits none); this fix
is TS-specific, so the fixture is kept TS-local (not in the shared
codegen-conformance corpus).
Claude-Session: https://claude.ai/code/session_01GF9xLEQZaPus5Y6opk398n
Co-authored-by: Doug Mealing <noreply@anthropic.com>
0 commit comments