Generating typescript types for client SDK

I’m working on a Next.js app and I’m fetching the data using “@datocms/cma-client-node” library.
I’m wondering if there is a way to generate Typescript types locally for the created models/blocks to use them in my components?

Similar to this article’s approache but for the Client from SDK instead of GraphQL queries: How To Generate TypeScript Types From GraphQL — DatoCMS

Hi @moatasem.ebrahim, and welcome to the Dato forums!

Unfortunately we don’t currently support TypeScript generation from our CMA API. The GraphQL generators depend on upstream type generation libs tied to GraphQL queries in particular.

However, if you generate the types from the GraphQL calls, that might get you like 70%-80% of the way there, and you can manually modify the resulting types (probably renaming field names from the GraphQL API’s camelCase to the CMA’s snake_case).

Can I ask if there’s a particular reason you want to use the CMA instead of the CDA in your Next project?

Hi Roger,
Thank you for the quick response.
I’m new to Dato CMS and I was didn’t know that the CMA and CDA are separated.
I checked them now and I’ll move to using CDA.

Thank you for your support.

1 Like

You’re welcome, and glad to hear it :slight_smile: Hopefully you’ll like the GraphQL API… it’s designed to make it easy for your frontend to pull exactly what it needs.

Welcome again to Dato, and please don’t hesitate to ask for help if you ever need it.