ssalbdivad
ssalbdivad
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
No description
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
But also all the .default types should enforce that whatever you pass is their input, so in most cases you'd just get an error if you did something like .default(false) in that case
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
There's a broader set of rules that essentialy any constraint you apply without .pipe or .narrow applies to the input. If you think about it it wouldn't really make sense any other way because usually if you just return something from a function we don't have any runtime representation to constrain
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
defaults and .optional both basically attach metadata that is used when the type is referenced in an object, not change the type itself
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
But if it just made the type accept undefined (which I've thought about) it would cause all sorts of inconsistencies in the type system
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
Yeah I need to elaborate a bit on that, but yes it's intentional. Initially, defaults could only be added within an object. I loosened that restriction to allow defaults to be specified as metadata so that if they were ever attached to an object, they'd then have the default value.
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
(this is in 2.0.0-rc.10)
174 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
All right there were a couple edge cases related to morphs that made it a bit more work than I anticipated but hopefully everything "just works" now. The default is actually precomputed as soon as you instantiate your validator if you morph it, so you skip the transform logic altogether from "off" and go straight to false at runtime 🎉 I've added both of these forms to unit tests, and hopefully the logic is developed in a way where however/whenver you add a default input, it should work out 🙏
const processForm = type({
bool_value: type("string='off'").pipe(v => (v === "on" ? true : false))
})

const processForm2 = type({
bool_value: type("string")
.pipe(v => (v === "on" ? true : false))
.default("off")
})
const processForm = type({
bool_value: type("string='off'").pipe(v => (v === "on" ? true : false))
})

const processForm2 = type({
bool_value: type("string")
.pipe(v => (v === "on" ? true : false))
.default("off")
})
174 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Really excited to see that come to fruition!
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Amazing! Then you'll publish it as an ecosystem library so that everyone can use it right? 🙏
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Looks clean!
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Yeah that looks a lot easier! It's even nicer if you're mapping a known set of keys because then you get strict inference for the defaults, but even if you are doing it generically and have to cast it still makes the runtime part of it a lot easier
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
It does seem like there's lots of type errors for me haha
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
It's unfortunate that return doesn't just error because it shouldn't match the mapped type
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
So what you'd want instead of:
return [prop, { key, value: value.or('string.numeric.parse') }]
return [prop, { key, value: value.or('string.numeric.parse') }]
is:
return {...prop, value: prop.value.or('string.numeric.parse') }
return {...prop, value: prop.value.or('string.numeric.parse') }
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
There should really only ever be one mapped prop per key
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
I'd expect them to intersect and if they're incompatible you'd get an error
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
What was the error you got?
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
You're adding multiple props of the same key?
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Yeah that doesn't look right
27 replies