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
Hello, I'm currently in the process of migrating a project to TypeScript, and have encountered some problems with nested linked content.
When formatting the data received from Contentful I map over the results and do some serialization of the data. But sometimes (I haven't figured out when) I don't get correct typings for the fields of a linked object.
In the following screenshot I've added prints of the types of different variables using the Two Slash Queries plugin.
I get an array of ApiReferenceSubsection into my function
I loop over them with a map, and the subsection is indeed typed correctly
I extract the table property from the fields of that subsection, and get the correct typing
But suddenly, when I try to access the fields of the table, I get a very generic type ([x: string]: string | number | boolean | JsonObject | JsonArray | Document | (string | Entry<EntrySkeletonType, "WITHOUT_UNRESOLVABLE_LINKS", string> | Asset<...> | undefined)[] | ... 4 more ... | undefined;)
I'm using contentful 10.6.5, and cf-content-types-generator 2.12.9.
I'm generating the types with cf-content-types-generator -g -s $CONTENTFUL_SPACE_ID -t $CONTENTFUL_MANAGEMENT_API_KEY -e $CONTENTFUL_ENV -X -o ./types/generated/contentful
The generated files for subsection and table are as follows:
importtype{ChainModifiers,Entry,EntryFieldTypes,EntrySkeletonType,LocaleCode}from"contentful";importtype{TypeApiObjectPropertySkeleton}from"./TypeApiObjectProperty";importtype{TypeTableSkeleton}from"./TypeTable";exportinterfaceTypeApiReferenceSubsectionFields{heading?: EntryFieldTypes.Symbol;text?: EntryFieldTypes.RichText;properties?: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<TypeApiObjectPropertySkeleton>>;table?: EntryFieldTypes.EntryLink<TypeTableSkeleton>;}exporttypeTypeApiReferenceSubsectionSkeleton=EntrySkeletonType<TypeApiReferenceSubsectionFields,"apiReferenceSubsection">;exporttypeTypeApiReferenceSubsection<ModifiersextendsChainModifiers,LocalesextendsLocaleCode>=Entry<TypeApiReferenceSubsectionSkeleton,Modifiers,Locales>;exportfunctionisTypeApiReferenceSubsection<ModifiersextendsChainModifiers,LocalesextendsLocaleCode>(entry: Entry<EntrySkeletonType,Modifiers,Locales>): entry is TypeApiReferenceSubsection<Modifiers,Locales>{returnentry.sys.contentType.sys.id==='apiReferenceSubsection'}
importtype{ChainModifiers,Entry,EntryFieldTypes,EntrySkeletonType,LocaleCode}from"contentful";exportinterfaceTypeTableFields{title: EntryFieldTypes.Symbol;data?: EntryFieldTypes.Object;}exporttypeTypeTableSkeleton=EntrySkeletonType<TypeTableFields,"table">;exporttypeTypeTable<ModifiersextendsChainModifiers,LocalesextendsLocaleCode>=Entry<TypeTableSkeleton,Modifiers,Locales>;exportfunctionisTypeTable<ModifiersextendsChainModifiers,LocalesextendsLocaleCode>(entry: Entry<EntrySkeletonType,Modifiers,Locales>): entry is TypeTable<Modifiers,Locales>{returnentry.sys.contentType.sys.id==='table'}
The text was updated successfully, but these errors were encountered:
And of course, just by writing this down in an issue I found what the problem was. This relates to this open issue: #296. My project has module: NodeNext and requires file extensions on imports. Adding .js manually to all imports in the generated files solved my problem.
Hello, I'm currently in the process of migrating a project to TypeScript, and have encountered some problems with nested linked content.
When formatting the data received from Contentful I map over the results and do some serialization of the data. But sometimes (I haven't figured out when) I don't get correct typings for the fields of a linked object.
In the following screenshot I've added prints of the types of different variables using the Two Slash Queries plugin.
ApiReferenceSubsection
into my functionsubsection
is indeed typed correctlytable
property from the fields of thatsubsection
, and get the correct typingtable
, I get a very generic type ([x: string]: string | number | boolean | JsonObject | JsonArray | Document | (string | Entry<EntrySkeletonType, "WITHOUT_UNRESOLVABLE_LINKS", string> | Asset<...> | undefined)[] | ... 4 more ... | undefined;
)I'm using
contentful
10.6.5, andcf-content-types-generator
2.12.9.I'm generating the types with
cf-content-types-generator -g -s $CONTENTFUL_SPACE_ID -t $CONTENTFUL_MANAGEMENT_API_KEY -e $CONTENTFUL_ENV -X -o ./types/generated/contentful
The generated files for
subsection
andtable
are as follows:The text was updated successfully, but these errors were encountered: