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

feat: give includes basic entry and asset types instead of any #2363

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

TimBeyer
Copy link
Contributor

Summary

Gives includes Entry and Asset arrays at least basic skeleton types.
From there they can then conveniently be narrowed down to the desired types.

Description

Currently the types are any, which is difficult to work with.
Casting from the outside is awkward too especially since we have the modifiers that should propagate.
So we should just set the correct types from the start.

Motivation and Context

I need to do some processing on the includes and don't want to cast them all the time.

@TimBeyer TimBeyer requested a review from a team as a code owner October 24, 2024 11:08
@TimBeyer TimBeyer requested review from Silhoue, veu and axe312ger October 24, 2024 11:09
@TimBeyer TimBeyer enabled auto-merge (squash) October 24, 2024 12:35
@@ -339,7 +339,7 @@ export type EntryCollection<
> = ContentfulCollection<Entry<EntrySkeleton, Modifiers, Locales>> & {
errors?: Array<any>
includes?: {
Entry?: any[]
Asset?: any[]
Entry?: Entry<EntrySkeletonType, Modifiers, Locales>[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not pass down the Locales variable here and use LocaleCode instead because linked entries might come from other spaces which can have different locales.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when we make cross-space requests we basically don't know anymore what locales we're dealing with?
That makes sense, but won't that then also already be broken in the more common case of actually using the link resolution, since there we cannot distinguish?

I'm a bit split between making it easy for the most common use case of not having cross space links, but a set of explicit locales, and ensuring that the types aren't misleading in the case where you use cross space links to spaces with a different set of locales.

I guess since the includes are also not returned in a structure where customers could provide something like a space / locale mapping that means we basically have no way to ever really have locale types that are anything other than string.

So I'm wondering, maybe it's better to keep using Locales which will probably in much more than 90% of cases be the expected behavior, and which you can at least put all the locales between the different spaces in as a workaround, instead of forcing includes to always have untyped locales.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you’re right. Even in most cross space cases the locales should be created to match and in cases that are more complicated the locale types probably won’t help much and have to be checked at runtime anyway in which case you would just use string and be correct.

Copy link
Member

@marcolink marcolink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👏
Maybe we can add a little paragraph to the docs describing the behaviour?

@TimBeyer TimBeyer disabled auto-merge October 25, 2024 07:44
@TimBeyer TimBeyer enabled auto-merge (squash) October 25, 2024 07:44
@TimBeyer TimBeyer merged commit f9bf2cc into master Oct 25, 2024
3 checks passed
@TimBeyer TimBeyer deleted the feat/add-includes-types branch October 25, 2024 14:54
@contentful-automation
Copy link
Contributor

🎉 This PR is included in version 11.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants