sanity icon indicating copy to clipboard operation
sanity copied to clipboard

import `client` from `@sanity-typed/client` instead of `@sanity/client`

Open xuzuodong opened this issue 2 years ago • 2 comments

@sanity-typed is a project completes Sanity's developer experience with typescript, which includes @sanity-typed/client with typed GROQ Results. It seems to be good if nuxt-sanity can optionally import client from this package. Is it possible to do so for better TypeScript DX?

xuzuodong avatar Feb 11 '24 13:02 xuzuodong

This is extremely cool. Would it be sufficient to allow the import to be configurable? Is it otherwise equivalent in API?

danielroe avatar Mar 07 '24 16:03 danielroe

I think the most intuitive way to do so is to add typedClient configuration in sanity field in nuxt.config.ts:

sanity: {
    projectId: 'myProject',
    typedClient: true // requires users to explicitly set
},

Although this may be conflict with another configuration minimal. Maybe we can mix the two features up and do something like:

sanity: {
    projectId: 'myProject',
    clientType: 'typed' // can also be 'minimal' or 'default', defaults to 'default'
},

In this way, the minimal configuration should be deprecated, and causes breaking changes though.

xuzuodong avatar Mar 19 '24 09:03 xuzuodong

For those who want better TypeScript DX, Sanity now introduces an experimental feature called Sanity TypeGen which supersedes @sanity-typed. Sanity TypeGen supports generate types via its CLI, so I think this issue can be closed now.

xuzuodong avatar Jun 02 '24 06:06 xuzuodong