How to handle checkbox in type('parse.formData').to(...)
I want turn the checkbox into boolean, but the checkbox field only produce "on" when checked, and missing when unchecked...
29 Replies
["'on' | 'off'", "=", "off"] works, but I cannot convert it to boolean
You need to tell ArkType how to convert the string to a boolean. I guess what you want is
but how to embed it with other propertities?
Wdym?
it just dont work
What's the error(s), and what version of ArkType are you ussing?
arktype=2.0.0-beta.5
error is chinese (but it basically mean cannot assign '=' to ....
Do you actually need the default value?
'default?' also doen't work
^ ???
this seems to work nvm, it fails at runtime
runtime error: Default values must be specified on objects like { isAdmin: 'boolean = false' }
Yeah, I just got the same when actually running it
That's probably a bug
If you don't need the default you can remove it and then it works properly
If you do need the default, then I guess the best option is to just make it optional
would work
yes, I think it would be perfect
Although in fairness there's no reason to use a default here
Because you're morphing to a boolean anyway, and so whether the value is
undefined
or "off"
the outcome is the same (both will give false
)the backend API use boolean, and I don't want to use two different types for it..
just created a new workaround: fix the formdata api
Fwiw I've created a bug report: https://github.com/arktypeio/arktype/issues/1089
GitHub
Unable to morph object values with default · Issue #1089 · arktypei...
Report a bug It seems it's currently impossible to morph and object value that has a default. 🔎 Search Terms object default, morph default 🧩 Context ArkType version: 2.0.0-beta.5 TypeScript ver...
Added a couple comments to the issue
Will definitely consider loosening some of these restrictions if I can find a sensible way to do it
Yeah, that's fair. I actually said above it doesn't really make sense to default here
I suppose the issue should be closed as "Won't Do" or w/e rather than "Completed"?
I think I already changed it
Still showing "Completed" for me :Shrug:
Oh I think I clicked that button but it only does something if I actually wrote a comment
But still, I would like to handle it better ideally, because I could just optimize the redundancy away like the type system does in a lot of other cases by applying the morph to the default value to update it
Just not worth handling as a one-off right now
Is it worth leaving the issue open for future tracking then?
Hmm
Could you create a brief feature request instead like "Precomputed morphs for default values"
Sure
Typed on my phone, so probs not perfect but here you go: https://github.com/arktypeio/arktype/issues/1090
GitHub
Precomputed morphs for defaults · Issue #1090 · arktypeio/arktype
Request a feature 🤷 Motivation Relates to #1089. This would optimise the redundancy away from morphed default types by moving the default assignment into the morph. For example: type({foo: ["&...
Yeah I already get notifications from https://discord.com/channels/957797212103016458/1090878931558731848 😛
Thank you!
I have a private channel that notifies me for anything on the repo, even just someone starring it 😅