Typescript Definitions for Schema Typing
See original GitHub issueIs your feature request related to a problem? Please describe.
There is no official way of typing schema definitions. Schema types would be useful in helping to prevent some death by a thousand cuts scenarios like forgetting to define a to
property in a reference
definition instead of very visually similar of
, which is used in an array
definition.
It would also be useful in reducing how often one must visit sanity.io/docs and search for usage instructions for just one aspect of a schema definition. Schema docs like sanity.io/docs/conditional-fields, sanity.io/docs/validation, and sanity.io/docs/schema-types are scattered around the site and aren’t grouped in any way for easy access to each other. I have to use search each time in order to find them individually. If the definitions are typed, the need to often visit docs for usage instructions is reduced.
Describe the solution you’d like Please provide official Typescript types for use in schema defintions to improve DX.
Describe alternatives you’ve considered
BaseSchemaType
from @sanity/types seems close, but its type
property does not work with strings, which makes it useless for this purpose.
Some are generating their own types in place of official ones: https://github.com/ricokahler/sanity-codegen/blob/main/src/generate-types.ts. But as new Sanity features are released, these definitions will always be going out of date.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:5 (4 by maintainers)
I’d like to throw my vote in for this. We use
sanity-codegen
for querying and consuming the docs (amazing! loving this) but typing the configs in the first place would be phenomenal. Having everything returned asany
like sanity docs have as a workaround basically means we shouldn’t use typescript here.This is far from perfect, but I created my own typings because of this issue. Maybe it can serve as a work around, or starting point for others until the @sanity/types is properly working.