I often use const assertions in my typescript models:
const ListingVehicleTypes = [
"car",
"motorcycle",
"caravan",
"camper_trailer"
] as const;
interface LISTING {
vehicleType: typeof ListingVehicleTypes[number];
...
}
As such, LISTING["vehicleType"] is correctly inferred as "car" | "motorcycle" | "caravan" | "camper_trailer".
Can I express such restrictions in my schema.prisma? Neither imports nor typescript utils are allowed in *.prisma files:
model Listing {
vehicleType typeof ListingVehicleTypes[number] // no-go
}
If not, is there a way to "enrich" the prisma models with the type-safer typescript models when prisma-powered DB queries are performed?
I can always cast the query bodies and responses to any but is there a cleaner approach?
For what it's worth, I'm using the mongodb provider -- but I don't think the provider plays a role here.