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
On top of that, a few of the API endpoints accept one of three parameters, file, uid, or periodic-note. Depending on the passed-in parameter, an internal object is looked up. So I figured I could write a function which extends the foundation, implements the one-of-three-params check, and enhances the output with a _computed key that stores a reference to the aforementioned internal object. Different endpoints have different additional parameters.
functiontargetedNoteSchema(additionalParams: z.AnyZodObject){returnincomingBaseParams.merge(additionalParams).extend({file: z.string().optional(),uid: z.string().optional(),"periodic-note": z.enum(["daily","weekly"]).optional(),}).refine((obj)=>["file","uid","periodic-note"].filter((key)=>keyinobj).length===1,{message: "Either 'file', 'uid', or 'periodic-note' must be provided"},).transform((incoming)=>{// Transformation happening here (this works)return{
...incoming,_computed: {someValue: "sure",},};});}
The problem I can't figure out: when I use the function, neither the keys from incomingBaseParams nor these of obj are part of the result's type.
I suspect that I'm just holding it hilariously wrong, nevertheless, I'm stuck. It's been a long week already, and I'd appreciate any help you folks might be able to give. Thanks in advance!
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
-
Hi. I use zod to validate incoming API calls. Many of these calls are similar, all share this common foundation:
On top of that, a few of the API endpoints accept one of three parameters,
file
,uid
, orperiodic-note
. Depending on the passed-in parameter, an internal object is looked up. So I figured I could write a function which extends the foundation, implements the one-of-three-params check, and enhances theoutput
with a_computed
key that stores a reference to the aforementioned internal object. Different endpoints have different additional parameters.The problem I can't figure out: when I use the function, neither the keys from
incomingBaseParams
nor these ofobj
are part of the result's type.I suspect that I'm just holding it hilariously wrong, nevertheless, I'm stuck. It's been a long week already, and I'd appreciate any help you folks might be able to give. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions