Generating TypeScript Types from Contentful

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

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!

josuesuarezcampos
Автор

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

brianstanback
Автор

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<TypeAuthorFields>;

DlSechi