In my TypeScript models, I frequently utilize const assertions:
const ListingVehicleTypes = [
"car",
"motorcycle",
"caravan",
"camper_trailer"
] as const;
interface LISTING {
vehicleType: typeof ListingVehicleTypes[number];
...
}
This results in LISTING["vehicleType"]
being accurately inferred as
"car" | "motorcycle" | "caravan" | "camper_trailer"
.
Is it possible to impose such restrictions in my schema.prisma
? Imports and TypeScript utilities are prohibited in *.prisma
files:
model Listing {
vehicleType typeof ListingVehicleTypes[number] // not allowed
}
If not, how can I integrate the type-safe TypeScript models with Prisma when conducting database queries?
I could always resort to casting query bodies and responses to any
, but is there a more elegant solution?
Just to mention, I'm utilizing the mongodb
provider -- although I don't believe the provider has any impact in this scenario.