SneakyTurtle
Aarktype
•Created by SneakyTurtle on 6/4/2024 in #questions
Wrapper around `type()`
In my configuration loader that I'm building, I have a "registry" pattern where I want to have developers declare the type schema of the config they expect, and then they need to register the config in order to get it loaded, looks something like this:
But I don't love having
registerConfig()
wrapped around type()
, instead I would love to just have the second parameter to the register function be passed through from type()
so that I could call type()
internally, i.e.
This is ideal as it avoids the need to import both my config library and arktype, as well as just being simpler for the consumer of my library.
The problem I'm having is that Parameters<typeof type>[0]
is not resolving correctly. Is there a better way to get to that type?88 replies
Aarktype
•Created by SneakyTurtle on 6/1/2024 in #questions
Runtime coercion
I'm building a system to load declarative runtime configuration from a couple different sources, all of which provide values as strings (env vars, AWS SSM Parameters).
Currently I'm walking through the
typeJson
at runtime to build accessors for each field, such as joining field names with __
to build environment variable keys, and that is working great. I can cleanly detect when I reach a "leaf" type to load, and I either have a string or an object with a "domain"; my challenge is whether there is an elegant way of coercing the string I load into the type expected at this point (without making some huge imperative logic block).
I'm hopeful there might be some clever thing under the hood that I can use in place of rolling my own.
Also, are there types defined somewhere that more concretely describe the typeJson
structure?43 replies