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.