Skip to content

Add a list of forbidden Custom Types IDs to the docs, to avoid errors while generating types #50

@albanbleicher

Description

@albanbleicher

Problem:

I had an issue while generating types for Custom Types with id items. You can see the logs below.

TypeError: Cannot read properties of undefined (reading 'model')
    at file:///Users/alban/[...]/node_modules/.pnpm/[email protected]_zdskoi4kizcgcz3c254mxvxata/node_modules/prismic-ts-codegen/dist/lib/getAPIIDPath.js:11:52

The logs were not very clear and I had to dig into the package to find that items fits a conditions that triggers the errors.

The code that triggers the error is located at prismic-ts-codegen/dist/lib/getAPIIDPath.js and specifically this condition :

if (element.id === "items") {
        const previousElement = config.path[i - 1];
        if (isCustomTypeModelSlice(previousElement.model) || isSharedSliceModel(previousElement.model)) {
          return `${element.id}[]`;
        }
      }

Describe the solution you'd like

This could be avoided in the future by providing a list of forbidden Custom Types IDs, or even better, blocking the creation of Custom Types with forbidden IDs in the first place :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions