cf-content-types-generator icon indicating copy to clipboard operation
cf-content-types-generator copied to clipboard

Why can `EntryFieldTypes.Array<EntryFieldTypes.EntryLink<EntrySkeletonType>>` array include `undefined`?

Open Shintarot opened this issue 1 year ago • 0 comments

Environment

VSCode 1.87.2 (Universal) on Darwin x64 21.6.0
"typescript": "^5.4.2",
"@types/node": "^20.11.28",
"contentful": "^10.8.1",
"contentful-cli": "^3.1.44",
"cf-content-types-generator": "^2.15.0",

cf-content-types-generator -X -s ${CONTENTFUL_SPACE_ID}  -t ${cmaToken} -o ${outDir}

Actual Behavior

There is a References, many field in the configuration pictured below.

app contentful com_spaces_mxid377r9ws5_content_types_report_fields app contentful com_spaces_mxid377r9ws5_content_types_report_fields (1)

The type of this field is defined as EntryFieldTypes.Array<EntryFieldTypes.EntryLink<TypeXXXXSkeleton> (TypeXXXXSkeleton is my custom type.).

According to the editor, this type is actually (TypeXXXX | undefined)[].

Why can't it be TypeXXXX[]?

Possible reason

When the Entry specified in References, many is missing (deleted), Contentful returns undefined in the array?

Expected Behavior

If the referenced Entry does not exist, it is a problem on the source side (an Entry that does not exist should not be able to be referenced), so I think it should not be included in the array.

References, many field should not be typed as (TypeXXXX | undefined)[] but TypeXXXX[].

Shintarot avatar Mar 17 '24 06:03 Shintarot