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

V10 Types for Linked Fields that Allow Multiple Entries #2216

Closed
ryancooper7 opened this issue May 2, 2024 · 2 comments
Closed

V10 Types for Linked Fields that Allow Multiple Entries #2216

ryancooper7 opened this issue May 2, 2024 · 2 comments

Comments

@ryancooper7
Copy link

Expected Behavior

Using the new V10 Types, the following type definition is generated for a linked field that allows multiple entries, and has WITHOUT_UNRESOLVABLE_LINKS as a chain modifier:

(Entry<ContentTypeSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string> | undefined)[] | undefined

I understand that with the withoutUnresolvableLinks option passed to the client, that a single linked entry field could possibly be undefined, for example if the content delivery API is used and a piece of linked content is unpublished.

It doesn't make sense to me however, that there could be undefined values within the array of entries. Wouldn't the API response remove any unresolvable links, making it so that the array could be either empty or containing entries, but not containing undefined?

This would suggest to me that the type should actually be: (Entry<ContentTypeSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>)[] | undefined

Actual Behavior

In the type for a field with a chain modifier of WITHOUT_UNRESOLVABLE_LINKS, the returned type is an array of entries and undefined values

Possible Solution

Remove undefined from the array type resulting from a field with multiple linked entries and with WITHOUT_UNRESOLVABLE_LINKS

Steps to Reproduce

  1. Create a field type that is an array of linked entries using the V10 types:

EntryFieldTypes.Array<EntryFieldTypes.EntryLink<OtherContentTypeSkeleton>>

Context

This leads to null checks within arrays of linked entries that appear unnecessary

Environment

  • contentful 10.9.1
@ghost
Copy link

ghost commented May 9, 2024

I think they exist to represent missing entries.

@veu
Copy link
Contributor

veu commented Jun 5, 2024

Wouldn't the API response remove any unresolvable links, making it so that the array could be either empty or containing entries, but not containing undefined?

The API returns the resolved entries separately and the library adds them in the right places in your entries. When doing so in lists we could remove the links that could not be resolved but then you’ll get a shorter list and couldn’t tell which of the entries could not be resolved. In some use cases the position of list items matter so we need to keep each item in the list.

You can always use Array.filter to get a list with the undefined items removed.

@veu veu closed this as completed Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants