You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to ensure that the value passed as the default argument for the enum (e.g. { default: "FREE" }) is a valid value of the enum (i.e. ["FREE", "PREMIUM"]).
At the moment I am able to pass anything (e.g. .enum("type", PlanType, { default: "SOMETHING" })).
The text was updated successfully, but these errors were encountered:
FWIW I had a little play with this and it ends up looking like
exportclassPrismaEnum<Values=never>{privateenumMap: Map<string,string|undefined>=newMap();constructor(publicreadonlyname: string){}publicaddValue<Values,Valueextendsstring>(this: PrismaEnum<Values>,value: Value,options?: PrismaEnumOptions): PrismaEnum<Values|Value>{// We need to return a new instance with a cloned `enumMap` // for the types to do what we want.// If we modify `enumMap` in place then the type of `this` will be "wrong".constclone=newPrismaEnum(this.name);clone.enumMap=newMap(this.enumMap);clone.enumMap.set(value,options?.map);returnclone;}// ...etc}
Are we looking for Intellisense/Type-checking, or runtime checks?
Since, as @jmackie specified, the values are altered in place we'd have to go a roundabout way of making the values available to the TypeScript language server. One way would be to return the value of the alteration and build the strings onto the enum constructor type. Otherwise, we could have it default to "string" as we currently do.
Given an enum
and a model
I want to ensure that the value passed as the default argument for the enum (e.g.
{ default: "FREE" }
) is a valid value of the enum (i.e.["FREE", "PREMIUM"]
).At the moment I am able to pass anything (e.g.
.enum("type", PlanType, { default: "SOMETHING" })
).The text was updated successfully, but these errors were encountered: