Stuart B
Aarktype
•Created by Cobain on 10/9/2024 in #questions
Function which receives a arktype's 'type'
Good to know!
13 replies
Aarktype
•Created by Cobain on 10/9/2024 in #questions
Function which receives a arktype's 'type'
try:
13 replies
Aarktype
•Created by Stuart B on 9/30/2024 in #questions
Identifying a Date value in an object type
I'm feeling guilty about causing you extra work now. But it is very much appreciated.
39 replies
Aarktype
•Created by Stuart B on 9/30/2024 in #questions
Identifying a Date value in an object type
Thanks,good to know. I've just about got it working with the map() api now, where it seems to work as expected.
39 replies
Aarktype
•Created by Stuart B on 9/30/2024 in #questions
Identifying a Date value in an object type
Seems like the problem wasn't what I thought it was.
I tried value.json and I still have an issue.
I'm iterating through a type (validator) using
And using
to get the value.
This works for number, boolean, string. But when I try it with a Date, value.json returns
No sign of 'Date' anywhere.
Maybe I'll have to try rewriting using .map(). (I tried before, but Typescript was giving me all sorts of problems I couldn't work out, so I stuck with the old .internal.distribute)
39 replies
Aarktype
•Created by Stuart B on 9/30/2024 in #questions
Identifying a Date value in an object type
Sorry, misunderstanding. I'm not trying to identify a date ibject, I'm trying to identify a type that allows a date object.
39 replies
Aarktype
•Created by Stuart B on 9/25/2024 in #questions
Post-morph constraints not checked if constraints not met on another property
Chipping in as a fairly ignorant user (of ArkType) here... I'd imagine a lot of people wanting to use ArkType as part of a form validation process. With the current behaviour, you can't get full errors to your app user about what's wrong with an input form using the obvious approach. You end up with an error or two for the user to correct, they do so, and then another one pops up.
It seems the only way round that is to not use ArkType to do the data transformation from FormData strings into numeric. I don't think it's the behaviour most people would expect and is bound to cause a bunch of confusion.
If it stays the way it is, I think the docs should highlight this issue and maybe provide a suggested approach for form validation, as it's such a common use case.
188 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
That's great David, thanks!
I think it would be worth clearly mentioning in the docs that defaults refer to the input type, regardless of where you assign them. It's pretty obvious with 'string="off"', but if you add a .default() after the morph, I expect some people will assume that it applies to the morphed type.
Also, something like type('string|boolean=false') doesn't work. If there is no value passed then false as a default is not applied. If that's intentional (and I can see why it's a weird thing to do), then should it give a type error in the editor, rather than just ignore it?
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
It is such a relief that it wasn't me being an idiot!
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
Hi @ArkDavid , just to close this off, is the above example the way I need to go with this, or is there an approach that doesn't require 2 preprocess steps? I'm happy with either answer.
And sorry for my ignorance, if that's what it is. You're doing a very impressive job with Arktype!
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
I'm still missing something.
The below is the simplest example of what I want to do. This works, but it requires me to generate 2 preprocessing types, one to make sure there is a string value present and the second to transform the string value to a Boolean.
I can't get my head around why that can't be combined into one preprocessing step.
It seems like adding the 'string="off"' default to the second preprocess type should work, but it just ignores it. And I can't put the logic in the morph, as the morph doesn't run if it doesn't get a string value. Maybe I just have to accept "that's just the way it is, deal with it"!
It seems like adding the 'string="off"' default to the second preprocess type should work, but it just ignores it. And I can't put the logic in the morph, as the morph doesn't run if it doesn't get a string value. Maybe I just have to accept "that's just the way it is, deal with it"!
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
It's sort of the opposite of 1089. I can apply the morph ok but the defaults on the initial type get ignored. Is that the same cause?
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
I know it's controversial but I find snake_case easier to read.
I agree camelCase somehow looks better and is the js standard, but I find it easier to follow my code using snake_case.
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
So what's happening is that if I don't have a 'is_male' (e.g. a checkbox is not checked) then the default is not being applied to an optional field so I end up with no 'is_male' value in the output, when I need false.
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
I then pass this type through the function to get a modified type that is used to validate form input.
If I then try to validate this data:
I run into a problem with the default. The default for 'name' works ok. 'name' is a string input in both the original and modified types.
But the defaults for age and is_male get lost, even though I have pipe the string through original with .pipe(value).
That .pipe(value) is retaining the >18 number constraint on age but losing the =19.
I've tried adding .default() into the function but it makes no difference.
What am I missing?
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
I'm stuck again! (It's getting a bit embarrassing now, sorry David!).
This is a section of my current code.
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
Sounds good. And once again, thanks for the help!
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
Is there an easy(ish) way that I can force any boolean to be optional in the new type? (Because for this use case, it always will be, as I'll receive 'on' or nothing at all)
174 replies
Aarktype
•Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
My points/questions:
1. In the examples above in this thread, the "detection" of a Boolean field in the type is done by checking value.extends('boolean'). For some reason I don't understand, that doesn't work here but value.overlaps('boolean') does. My assumption here is that I'm being an idiot, but I can't work out where.
2. In Plat's conform parser I see that value.or('string.numeric.parse') is used for a number field. This works but seems to mean that and numeric constraints that were on the original numeric field definition don't apply when it's parsed from a string. So I tried type('string.numeric.parse').pipe(value), which seems to keen any original numeric constraints.
3. The below works for numbers, but Boolean is causing me problems. The original type has the Boolean as an option (as an unchecked checkbox on a form won't provide a value in formData). But the function is converting the optional key back into required. So it works if a checkbox is checked and passes 'on' but doesn't work if it is unchecked.
174 replies