prisma type error on union type stored as json

I am trying to convert my Cloud Firestore project to supabase due to some issues I have had with transactions. I have the following types in my code:
export interface RoundOptions {
name: string;
scoreToWin: number;
}

export interface BracketOptions {
name: string;
defaultScoreToWin: number;
rounds: RoundOptions[];
}

export interface SingleEliminationOptions {
type: "single_elimination";
winAnnotations?: string[];
brackets: [BracketOptions];
}

export interface DoubleEliminationOptions {
type: "double_elimination";
winAnnotations?: string[];
brackets: [BracketOptions, BracketOptions];
}

export type FormatOptions = SingleEliminationOptions | DoubleEliminationOptions;
export interface RoundOptions {
name: string;
scoreToWin: number;
}

export interface BracketOptions {
name: string;
defaultScoreToWin: number;
rounds: RoundOptions[];
}

export interface SingleEliminationOptions {
type: "single_elimination";
winAnnotations?: string[];
brackets: [BracketOptions];
}

export interface DoubleEliminationOptions {
type: "double_elimination";
winAnnotations?: string[];
brackets: [BracketOptions, BracketOptions];
}

export type FormatOptions = SingleEliminationOptions | DoubleEliminationOptions;
And this is my prisma schema I am using for experimentation:
model Tournament {
id String @id
data Json
}
model Tournament {
id String @id
data Json
}
In my code I am trying to do:
await ctx.prisma.tournament.create({
data: {
id: tournament.id,
data: tournament.formatOptions, // This hsa the type FormatOptions
},
});
await ctx.prisma.tournament.create({
data: {
id: tournament.id,
data: tournament.formatOptions, // This hsa the type FormatOptions
},
});
But I am getting this error. Can someone help me understand whats going wrong?
Solution:
Figured it out. In case anybody cares, prisma requires types not interfaces to make this work
Jump to solution
2 Replies
Tom
TomOP2y ago
i would get prisma being confused about the type if i tried to get everything into relational rows / columns, but this is supposed to be just json
Solution
Tom
Tom2y ago
Figured it out. In case anybody cares, prisma requires types not interfaces to make this work
Want results from more Discord servers?
Add your server