Generate types from postgres JSON Schemas #11971
Replies: 5 comments
|
Currently to not get errors in vs code, i am manually changing the type Json(generated by supabase cli) to this 👇 Initial(generated) export type Json = string | number | boolean | null | { [key:string]: Json } | Json[]Manual export interface Json {
[key: string]: Json | string | number | boolean | Json[]
} |
|
Even cooler would be to use something like https://www.npmjs.com/package/json-schema-to-typescript to convert the actual JSON Schema constraint into a type during typegen. :) |
|
After watching this video https://www.youtube.com/watch?v=amJo48ChLGs Everyone will agree that this is an awesome feature to add |
|
I'd like to see the other way around, generate JSON schemas from the database |
|
It's not so simple because the functions in this case the schemas are just part of the function, there's no realistic way for Supabase to get at them. In order to make this possible, I could imagine a more sophisticated extension than With something like this, Supabase could figure out which json schema is being used for each column and provide the appropriate types when doing |
Uh oh!
There was an error while loading. Please reload this page.
I would find it valuable if the supabase cli could generate TypeScript types from JSON schemas defined with
pg_jsonschema.All reactions