question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript types for schema

See original GitHub issue

We are writing our site in typescript, using Gatsby and React. It would be great if the Sanity schema could be compiled to typescript interfaces, so that we could leverage static type safety during development.

I imagine generating this with a sanity cli command.

Given the translation layers between Sanity, GraphQL and TypeScript, I imagine this is is a subtle problem. If there’s any more info I can provide to be helpful, let me know.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:55
  • Comments:30 (12 by maintainers)

github_iconTop GitHub Comments

28reactions
phil-lgrcommented, Apr 6, 2022

Sorry to pollute this thread and the ironic tone, but … IMO Sanity in 2022 should have 100% TypeScript support, hell, all the init/sample projects should be scaffolded in TS

What is the point of GROQ Graphql, etc if everything in sanity (by default) is in plain JS?

image

Does anyone want to write any schema or plugin without TS today? Coming from other CMEs and framework, I am baffled by those schema files with 0 autocomplete or types

Edit:

The official docs have so little on that topic: https://www.sanity.io/docs/using-typescript-in-sanity-studio

24reactions
wommycommented, Apr 8, 2022

Sorry to pollute this thread and the ironic tone, but … IMO Sanity in 2022 should have 100% TypeScript support, hell, all the init/sample projects should be scaffolded in TS

What is the point of GROQ Graphql, etc if everything in sanity (by default) is in plain JS?

image

Does anyone want to write any schema or plugin without TS today? Coming from other CMEs and framework, I am baffled by those schema files with 0 autocomplete or types

Edit:

The official docs have so little on that topic: https://www.sanity.io/docs/using-typescript-in-sanity-studio

100% this

my mind was so boggled by how they took all the time for TS yet didnt pass any of that on

still 🤯🤯

Read more comments on GitHub >

github_iconTop Results From Across the Web

google/schema-dts: JSON-LD TypeScript types for ... - GitHub
schema -dts provides TypeScript definitions for Schema.org vocabulary in JSON-LD format. The typings are exposed as complete sets of discriminated type unions, ...
Read more >
typescript-json-schema - npm
typescript -json-schema generates JSON Schema files from your Typescript sources. Latest version: 0.55.0, last published: a month ago.
Read more >
Typescript Type of JSON schema object - Stack Overflow
Is there a special type associated with JSON-schema objects in typescript? My class has a method that checks whether its members satisfy the ......
Read more >
Schemas and Elements in TypeScript - iTwin.js
A Schema represents an ECSchema in TypeScript. It is a collection of Entity-based classes. See the BIS overview for how ECSchemas are used...
Read more >
Schemas in TypeScript - Mongoose
Mongoose schemas are separate from TypeScript interfaces, so you need to define both a document interface and a schema until V6.3.1. Mongoose supports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found