Default number
Hello!
Setting this brings the expected result, when ran through
inferAmbient
:
But adding a default value returns a function signature:
How can I get the number
type in the editor when providing a default value?86 Replies
It's not clear to me what exactly you're after here, but maybe
t["infer"]
or t["tOut"]
is what you're after?
Where t
in this case is your queryType
Yeah you probably want
t.infer
for the output or t.inferIn
for the input type (would allow undefined
). tOut
is more internal as it contains constraint brandsThank you!!!
inferIn
is exactly what I needed
I am using Arktype as my form, params and query schema, and am inferring the types from the schema for type-safe endpointsIf you want to create it from typed input, there's also a
from
method that accepts it
Like queryType.from({})
Would result in {page: 1}
And if I do
the result will be {page: 20}?
Yeah it should
So for form parsing it's a better variant than doing
?
If you're ever passing in known data like that, I'd use
from
so you get type safety
The default method is for accepting unknown
Actually it was
infer
, for the output as you said ๐
But other than that, they both produce the same result on runtime?Yes, under the hood it just calls
assert
which is also identical to the base method other than that if there are errors, it will throw instead of returning an errors object
But it looks like in a case like that where you're passing an object literal there should never be errorsThere will be errors if someone passes a wrong type
So in your case
queryType({page: 20})
is just an exam,pleIf they send
But doesn't TS enforce that anyways?
or would they not really be passing an object literal
It seems like if they passed something invalid you would want to throw
They're always passing an object literal (Remix converts formData and query params into an object), but they might be passing wrong keys or types if they'll call it through some other client than the website