Replies: 1 comment 1 reply
-
Actually this is a subtle bug with the way specifically If you mouse over the type itself, you'll see this: const myOpts: Type<{
callback: (...args: any[]) => unknown;
}> But it's incorrectly reduced to its return type, because we make the mistake of assuming it's a morph (i.e. a validator that accepts a given input type then transforms it). That said, generally speaking a validation library is not useful when validating functional values because they have no associated type at runtime. The only data you can determine about a function by actually inspecting the object at runtime is how many arguments it takes (will be its That said, you can easily compose ArkType validators to validate a function's input then run arbitrary logic (that's essentially what a morph is). That can be achieved like this: const getLength = morph("string", (s) => s.length)
// or
const getLength2 = type(["string", "|>", (s) => s.length])
// data is typed as number | undefined
const { data } = getLength("foo") I've logged a bug here #721 that I will address in the upcoming beta release to fix the general type of the |
Beta Was this translation helpful? Give feedback.
-
Hi,
Heard about ArkType off of Reddit and thought I'd check it out. I started playing with it, but am struggling to understand how it has a "1:1" relationship to TS. Does this mean that (theoretically) anything expressible in TS is expressible in ArkType?
So for example, I am building a small library. My library allows a consumer to provide it a function in a set of options. The function must be of a certain shape, but (and maybe this is just a documentation issue, since it's early) I couldn't figure out how to express a) the parameters and return value of the function, and b) how to express a "function" at all. Regarding b), the type of the options (via
typeof myType.infer
) hasunknown
where the function should be:Is this a use case that ArkType intends to cover? Or is it focused on validating user (e.g., web form) input?
Beta Was this translation helpful? Give feedback.
All reactions