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
We're using this tool as part of our TypeScript project. We have a prod site using the Content Delivery API, and we have a preview build that content editors use as part of Contentful's Live Preview, and that uses the Content Preview API.
The issue is that the Content Preview API will return content that does not conform to the types that this tool creates.
To replicate:
create a content model with a mandatory "title" field.
create a new (Draft) entry using this model, but do not populate the "title" field.
wait a short while, and this will get auto-saved in Contentful (even though the mandatory field is not yet populated). NB it is still "Draft" at this point.
the Preview API wil pull through this entry, as expected, because Live Preview needs to see Draft entries.
supposing that your code does something with this "title" field, you'll get type errors because the "title" field is undefined, yet the cf-content-types-generator does not allow that field to be undefined.
For example suppose that you use the .includes() string function on title: if (entry.fields.title.includes("foo")) {
You would get the error: Cannot read properties of undefined (reading 'includes') TypeError: Cannot read properties of undefined
To fix, I think every field should include undefined in the type definition, just like optional fields do, even if that field is mandatory. This would then ensure that the developer must do: if (entry.fields.title?.includes("foo")) {
The text was updated successfully, but these errors were encountered:
We're using this tool as part of our TypeScript project. We have a prod site using the Content Delivery API, and we have a preview build that content editors use as part of Contentful's Live Preview, and that uses the Content Preview API.
The issue is that the Content Preview API will return content that does not conform to the types that this tool creates.
To replicate:
undefined
, yet the cf-content-types-generator does not allow that field to beundefined
.For example suppose that you use the .includes() string function on
title
:if (entry.fields.title.includes("foo")) {
You would get the error:
Cannot read properties of undefined (reading 'includes') TypeError: Cannot read properties of undefined
To fix, I think every field should include
undefined
in the type definition, just like optional fields do, even if that field is mandatory. This would then ensure that the developer must do:if (entry.fields.title?.includes("foo")) {
The text was updated successfully, but these errors were encountered: