From f08eb4e6dec57deda277697dd74881626e55d046 Mon Sep 17 00:00:00 2001 From: tomaboro Date: Wed, 8 Apr 2026 15:30:23 +0200 Subject: [PATCH 1/2] fix: use slice `id` instead of `name` for generated TypeScript types `prismic-ts-codegen` generates slice type names based on the slice `id`, not the `name`. When a slice has a mismatch between its `id` and `name` (e.g. a slice created by the content modeling agent), the generated component references a type like `Content.${pascalCase(name)}Slice` that doesn't exist, causing a TypeScript error. This fix passes the slice `id` through to the template and uses it for the `Content.*Slice` type reference, while keeping `name` for the human-readable component name and comments. Made-with: Cursor --- src/adapters/nextjs.templates.ts | 7 ++++--- src/adapters/nextjs.ts | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/adapters/nextjs.templates.ts b/src/adapters/nextjs.templates.ts index 3f6c8e7..34ea4ba 100644 --- a/src/adapters/nextjs.templates.ts +++ b/src/adapters/nextjs.templates.ts @@ -17,10 +17,11 @@ const SLICE_MARKUP = dedent` ) `; -export function sliceTemplate(args: { name: string; typescript: boolean }): string { - const { name, typescript } = args; +export function sliceTemplate(args: { name: string; id: string; typescript: boolean }): string { + const { name, id, typescript } = args; const pascalName = pascalCase(name); + const pascalId = pascalCase(id); const TS = dedent` import { FC } from "react"; @@ -30,7 +31,7 @@ export function sliceTemplate(args: { name: string; typescript: boolean }): stri /** * Props for \`${pascalName}\`. */ - export type ${pascalName}Props = SliceComponentProps; + export type ${pascalName}Props = SliceComponentProps; /** * Component for "${name}" Slices. diff --git a/src/adapters/nextjs.ts b/src/adapters/nextjs.ts index 37753c7..1a79433 100644 --- a/src/adapters/nextjs.ts +++ b/src/adapters/nextjs.ts @@ -48,6 +48,7 @@ export class NextJsAdapter extends Adapter { const componentPath = new URL(`index.${extension}x`, appendTrailingSlash(sliceDirectory)); const contents = sliceTemplate({ name: model.name, + id: model.id, typescript: await checkIsTypeScriptProject(), }); await writeFileRecursive(componentPath, contents); From 3de5544821d7bf71e19c7d3085fcfb856c4c3e96 Mon Sep 17 00:00:00 2001 From: tomaboro Date: Wed, 8 Apr 2026 16:29:42 +0200 Subject: [PATCH 2/2] refactor: apply code review --- src/adapters/nextjs.templates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/nextjs.templates.ts b/src/adapters/nextjs.templates.ts index 34ea4ba..fce35bc 100644 --- a/src/adapters/nextjs.templates.ts +++ b/src/adapters/nextjs.templates.ts @@ -45,7 +45,7 @@ export function sliceTemplate(args: { name: string; id: string; typescript: bool const JS = dedent` /** - * @typedef {import("@prismicio/client").Content.${pascalName}Slice} ${pascalName}Slice + * @typedef {import("@prismicio/client").Content.${pascalId}Slice} ${pascalName}Slice * @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props * @type {import("react").FC<${pascalName}Props>} */