contentful-typescript-codegen icon indicating copy to clipboard operation
contentful-typescript-codegen copied to clipboard

Property 'json' does not exist on type 'Document'.

Open angelod1as opened this issue 5 years ago • 1 comments

I'm querying Contentful with GraphQL and it returns me content?: Document | undefined.

In order to render the file I need to access content.json, using @contentful/rich-text-html-renderer, and it works. The issue is that Typescript keeps warning me that Property 'json' does not exist on type 'Document'. even though it surely does.

Is the typing wrong? Is something to do with the typings this library provides or something else?

angelod1as avatar Nov 26 '20 23:11 angelod1as

I am running into this same issue and have to do manual transforming to match the generated Document model, like so: // Need to map GraphQL response to match model, an 'item' is of Document type return fetchResponse?.data?.postCollection?.items.map((x) => { return { ...x, content: x.content.json }; });

This is not ideal, of course.

danfusaro avatar Dec 16 '21 15:12 danfusaro