A
arktype2mo ago
frolic

examples of URLSearchParams

are there any examples of using arktype to turn URLSearchParams into a well formed, typed object? I see things like Headers are supported as types, but didn't see URLSearchParams
4 Replies
ssalbdivad
ssalbdivad2mo ago
Hey nothing like this exists yet as a keyword. Would definitely be interested in a PR if you are up for it!
frolic
frolicOP2mo ago
I see there's a way to parse FormData into an object, and I suspect Headers and URLSearchParams would be quite similar (iterate and build up an object, except without File type) thoughts on consolidating these under a single parser? like Map? I guess these aren't true maps, just map-like iterables, because they can contain duplicate keys
frolic
frolicOP2mo ago
also noticed this, is this an accurate description? because the code seems to do something else
No description
ssalbdivad
ssalbdivad2mo ago
Yeah that definitely looks wrong those are autogenerated seems like something went awry with the JSDoc parsing Yeah I don't know much about the nuances of parsing URLSearchParams but definitely if we can keep it as consistent as possible with the approach from FormData that would be ideal. Generally the types are organized into their corresponding TS keywords. Since FormData is a built-in TS type, it works 1:1 with that name and then related types like parse are grouped under it. I'd probably expect the same kind of structure for URLSearchParams, though would consider other types of groupings of similar transform types in the future.

Did you find this page helpful?