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

Why is there no EntryFieldTypes for Asset? #2203

Open
LookRain opened this issue Apr 9, 2024 · 5 comments
Open

Why is there no EntryFieldTypes for Asset? #2203

LookRain opened this issue Apr 9, 2024 · 5 comments

Comments

@LookRain
Copy link

LookRain commented Apr 9, 2024

I have an asset field in my content named featureImage, on my frontend I want to correctly type this field, however there's no suitable EntryFieldTypes that gives me the correct inference of the featureImage type

const res = await client.getEntries<{
      fields: {
        resource_title: EntryFieldTypes.Text;
        author: EntryFieldTypes.Text;
        summary: EntryFieldTypes.Text;

        featureImage: // how do I type this??
      };
      contentTypeId: string;
    }>();

res.items[0].featureImage.fields.file.url
                          ^ TS error

Expected Behavior

const res = await client.getEntries<{
      fields: {
        resource_title: EntryFieldTypes.Text;
        author: EntryFieldTypes.Text;
        summary: EntryFieldTypes.Text;

        featureImage: // how do I type this??
      };
      contentTypeId: string;
    }>();

res.items[0].featureImage.fields.file.url
                          ^ I should be able to type featureImage so that this can be correctly inferred

Actual Behavior

TS error

Possible Solution

How should I type asset fields?

Steps to Reproduce

Context

Environment

  • Language Version:
  • Package Manager Version:
  • Browser Version:
  • Operating System:
  • Package Version:
  • Which API are you using?:
@marcolink
Copy link
Member

Hey @LookRain,
here is an example of an entry with an image field - fully typed! maybe that helps

@emavitta
Copy link

got the same problem here. The example seems exactly like mine, still doens't work (i'm using nuxt3 and contentful 10.8.7)

@emavitta
Copy link

NVM, @marcolink your code is correct and works to me too.

Thanks

@LookRain
Copy link
Author

hi @marcolink thanks for the example.

it seems to work with getEntry but not with getEntries though.

@marcolink
Copy link
Member

@LookRain can you share an example where it's not working for you?

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

3 participants