diff --git a/.changeset/fix-ingest-assignability.md b/.changeset/fix-ingest-assignability.md new file mode 100644 index 0000000..eab87b3 --- /dev/null +++ b/.changeset/fix-ingest-assignability.md @@ -0,0 +1,5 @@ +--- +"@chkit/plugin-codegen": patch +--- + +Generate row types as type aliases instead of interfaces to satisfy TypeScript's Record assignability requirement. Fixes TypeScript error TS2322 when passing typed row arrays to ingest functions. diff --git a/packages/cli/src/plugin.test.ts b/packages/cli/src/plugin.test.ts index c05cd70..9bb9e1f 100644 --- a/packages/cli/src/plugin.test.ts +++ b/packages/cli/src/plugin.test.ts @@ -659,7 +659,7 @@ describe('plugin runtime', () => { expect(payload.outFile).toBe(outFile) const content = await readFile(outFile, 'utf8') - expect(content).toContain('export interface AppUsersRow') + expect(content).toContain('export type AppUsersRow = {') expect(content.endsWith('\n')).toBe(true) } finally { await rm(fixture.dir, { recursive: true, force: true }) diff --git a/packages/plugin-codegen/src/generators.ts b/packages/plugin-codegen/src/generators.ts index bf8f148..0c5fa3a 100644 --- a/packages/plugin-codegen/src/generators.ts +++ b/packages/plugin-codegen/src/generators.ts @@ -246,7 +246,7 @@ function renderTableInterface( interfaceName: string, options: Required ): { lines: string[]; findings: CodegenFinding[] } { - const lines: string[] = [`export interface ${interfaceName} {`] + const lines: string[] = [`export type ${interfaceName} = {`] const findings: CodegenFinding[] = [] const zodFields: string[] = [] @@ -279,7 +279,7 @@ function renderViewInterface( const kind = definition.kind === 'view' ? 'view' : 'materialized_view' return { lines: [ - `export interface ${interfaceName} {`, + `export type ${interfaceName} = {`, ' [key: string]: unknown', '}', '', diff --git a/packages/plugin-codegen/src/index.test.ts b/packages/plugin-codegen/src/index.test.ts index c93698e..4a5c314 100644 --- a/packages/plugin-codegen/src/index.test.ts +++ b/packages/plugin-codegen/src/index.test.ts @@ -272,7 +272,7 @@ describe('@chkit/plugin-codegen generation', () => { }) expect(result.content).toBe( - `// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nexport interface AppUsersRow {\n id: string\n email: string\n created_at: string\n}\n` + `// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nexport type AppUsersRow = {\n id: string\n email: string\n created_at: string\n}\n` ) expect(result.content.endsWith('\n')).toBe(true) expect(result.declarationCount).toBe(1) @@ -364,7 +364,7 @@ describe('@chkit/plugin-codegen generation', () => { }) expect(result.content).toBe( - `// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nimport { z } from 'zod'\n\nexport interface AppUsersRow {\n id: string\n email: string | null\n}\n\nexport const AppUsersRowSchema = z.object({\n id: z.string(),\n email: z.string().nullable(),\n})\n\nexport type AppUsersRowInput = z.input\nexport type AppUsersRowOutput = z.output\n` + `// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nimport { z } from 'zod'\n\nexport type AppUsersRow = {\n id: string\n email: string | null\n}\n\nexport const AppUsersRowSchema = z.object({\n id: z.string(),\n email: z.string().nullable(),\n})\n\nexport type AppUsersRowInput = z.input\nexport type AppUsersRowOutput = z.output\n` ) }) })