Generate types: "Json" type is incompatible with other types
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- postgresql, typescript
- Ambito
- databases
Direzione di ricerca
Parti dall’implementazione TypeScript della funzionalità di generazione dei tipi e segui il modo in cui le colonne json e jsonb di PostgreSQL diventano il tipo Json generato. Riproduci gli errori di assegnazione degli esempi TypeScript dell’issue, quindi verifica che il tipo generato possa essere usato con tipi di oggetti JSON specifici dell’applicazione senza l’incompatibilità segnalata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When using the generate types feature for your Database (which is mostly great), if your column type is json or jsonb, the generated type it gives you is this:
export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[]
This type is incompatible with any type you try to use it for. For example, if I'm using a column to hold an ingredient (this is hypothetical):
export interface Ingredient {
id: number
name: string
quantity: string
}
const result: Json = { id: 1, name: 'Berries', quantity: '1 cup' } // this is how the object will be typed using the generated types
const ingredient: Ingredient = result // Type '{ [key: string]: Json | undefined; }' is missing the following properties from type 'Ingredient': id, name, quantity(2739)
const ingredient2: Ingredient = result as Ingredient
// above results in:
// Conversion of type '{ [key: string]: Json | undefined; }' to type 'Ingredient' may be a mistake because neither type sufficiently
// overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
I have more examples of this in the typescript playground below. Given how error-prone it is to add a type for JSON data, can you please consider using any for Json types? We have to cast these values as any anyway because you cannot cast the type you are using, as demonstrated above.
To Reproduce
You can see this behavior on this TypeScript playground link:
Desktop (please complete the following information):
- OS: macOS
- Browser: Chrome 120
- Version of CLI: 1.93.0
- Version of supabase-js: 2.38.0
- Version of Node.js: 20.5.1
- Lingua principale
- TypeScript
- Stelle
- 1.2k
- Fork
- 224
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di supabase/postgres-meta
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
supabase/postgres-meta#1150 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
supabase/postgres-meta#1147 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
supabase/postgres-meta#1146 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
supabase/postgres-meta#1143 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
supabase/postgres-meta#1142 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di supabase/postgres-meta
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
rohitg00/agentmemory#1428 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
boxlite-ai/boxlite#1729 ·
I maintainer di solito rispondono entro 1 giorno
-
detectors enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
SM260845/readme-gen#1 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
angular/angularfire#3774 ·
I maintainer di solito rispondono entro 2 giorni