typescript - Problem med att använda ett gränssnitt när man skapar en resurs i Prisma
Jag har ett problem och jag vet egentligen inte hur jag ska lösa det. Jag definierade en kolumn i min Prism-tabell med typen Json
product_info Json?
Och jag gjorde ett gränssnitt för detta json
export interface IProductInfoAction {
price: number;
}
Men när jag försöker skapa resursen får jag detta fel
const action: Action = await this.prisma.action.create(
{
data: {
target: data.target,
duration: data.duration,
idle_time: data.idle_time,
filters: data.filters,
type: Type[data.type],
score: 0,
sessionId: data.sessionId,
searched_term: data.searched_term,
...(data.product_info ? {
product_info: data.product_info
} : {})
}
}
);
is not assignable to type ActionUncheckedCreateInput
Types of property product_info are incompatible.
Type IProductInfoAction | undefined is not assignable to type
NullableJsonNullValueInput | InputJsonValue | undefined
Type IProductInfoAction is not assignable to type
NullableJsonNullValueInput | InputJsonValue | undefined
Hur skulle jag fortfarande kunna behålla det gränssnittet? Jag behöver det i koden för att exakt veta varje definition av JSON-objekten i den kolumnen