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 created the type in TypeScript but multiple ways that I tried did not work:
using keyof to validate the potential key and accessing the schema from schmema.shape
using a union type (I found no way to make the second value depend on the first value)ipt
import{z}from"zod";constUser=z.object({name: z.enum(["markus","Jenny"]),role: z.enum(["admin","user"]),});typeUser=z.infer<typeofUser>;// Type I want to achivetypeValidTupleType={[KinkeyofUser]: [K,User[K]];}[keyofUser];consttuple: ValidTupleType=["name","markus"];consttupleToTest: [string,string]=["name","markus"];constparsedTuple:ValidTupleType= ???
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to verify if a given tuple of two strings is a valid key-value pair for a given schema.
sandbox
I created the type in TypeScript but multiple ways that I tried did not work:
Is this possible?
Thanks to everyone who is willing to help
Beta Was this translation helpful? Give feedback.
All reactions