Extracting defaults at runtime
Hello!
What is the canon way to extract the default values of the type on runtime? I'd like to uuse the defaults from the type as defaults in a form.
2 Replies
Well there's the new
.map
API but that's really more for going types => types.
I guess you could map to a type with units as the defaults, then extract out those units
https://github.com/arktypeio/arktype/blob/d544f780498adab1e10eb4690f913a4f0911f8da/ark/type/__tests__/objects/mapped.test.ts
Note TS is super finicky about how it infers some of these return types so you might have to annotate some of them if you need type safety, but that was always true in the past anyways at least now the logic is simpler 😛Thank you! I'll try this out!