Skip to content

Default link resolution has wrong types #2379

Description

Actual Behaviour

Here's the method I'm using for getting data from Contentful:

export type EntriesWithSlug = TypePageSkeleton | TypeBlogPostSkeleton;

export const getEntryBySlug = (contentType) =>
  async (slug) => {
    const entries = await client.getEntries<EntriesWithSlug>({
      content_type: contentType,
      "fields.slug": slug,
      include: 3,
    });

    const entry = entries.items[0];
    return entry;
  };

In documentation, in ADVANCED.md file, is written, that by default, the links will be resolved, and the ones that can't be resolved, will be treated as unresolved. And when checking the Entry in app, the links are resolved, but the return types are treating all links as unresolved.

So I can use something like:

   const someLinkedEntry = entry.fields.linkedEntry.fields.name

But typescript will suggest that linedEntry is unresolved

  const unresolvedEntry = entry.fields.linkedEntry.sys... <- which is wrong

If I use chain modifier, like withoutLinkResolution or withoutUnresolvableLinks the entry data is precisely the same as the types.

Environment

  • Language Version: node 20.13.1
  • Package Manager Version: pnpm 9.12.3
  • Package Version: "contentful": "^11.2.0",
  • Which API are you using?: Delivery

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions