Generating TypeScript Types from Contentful

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • While the Contentful Node SDK is fully typed, the content retrieved from the API is not. Here’s how I have handled generating types from Contentful content in previous projects.
    00:07 Project Setup
    00:42 Exporting Contentful Content
    03:14 Extending Generated Types
    08:27 Using Generic for Common Types
    09:19 Closing
    #contentful #cms #webdevelopment #typescript

Комментарии • 4

  • @DlSechi
    @DlSechi Год назад +3

    Hello! Ty for this great tutorial! I have a problem. When I generate the types, it doesn't come with the sections in it. It throws an Error on the export saying that the type is missing the fields and contentTypeId. Can you help me pls? this is what it generates:
    import type { Asset, Entry, EntryFields } from "contentful";
    export interface TypeAuthorFields {
    name: EntryFields.Symbol;
    description: EntryFields.Text;
    avatar: Asset;
    }
    export type TypeAuthor = Entry;

    • @gergoradeczki
      @gergoradeczki Год назад +1

      `cf-content-types-generator` did not receive an update in a long time, but the `contentful` package did. So, they are out of sync right now.
      Downgrade to like _10.0.0-beta-v10.8_ the `contentful` package and you should be good to go.

  • @josuesuarezcampos6714
    @josuesuarezcampos6714 Год назад +1

    This is awesome. I was tired of trying to figure it out how to write all the types properly. Now we can do it automatically!

  • @brianstanback360
    @brianstanback360 4 месяца назад

    Thanks very helpful, I had to add a --v10 argument when generating the types to make it play nicely with v10 of the contentful SDK