Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
albanbleicher opened this issue Jun 12, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@albanbleicher
Copy link

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 :)

@albanbleicher albanbleicher added the enhancement New feature or request label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant