Type.any but with specific scope?
Is there a way to use type.any but with the scope bound to some type?
My use case is that I have a special scope that does some magic for internationalization and I need a way to wrap (or just refer to) types externally (like on the website example) but with the scope bound to my special Scope
12 Replies
Type<unknown, MyScope>
But then I lose the type safety of knowing T right? (And “infer” and “inferIn”) fields?
Well
type.Any
doesn't know the T either... that's the point of itYou can have a function foo<T>(x: type.Any<T>)
Right... So do
foo<T>(x: Type<T, MyScope>)
then?Hmm, right, it does, but then what is Any for?
In my particular use case Type<T, MyScope> works fine (inference and all), for most types but not for piped types (
Type<(In: {})> => Out
) and I thought Any would fix it, but apparently that's an issue either with Any as well, sorry for starting this thread
Any just for anyone stumbling on the same issue, inference is somewhat broken with this, but overloading your function will fix it (snippet from my code):
Yeah, you shouldn't use
T
in the return for this very reason
What you likely want is
Because T["Infer"]
will handle pipes, defaults, etc.Adapter<T> is one of my wrappers (it wraps superforms validator, and it does use T["infer"]), but thanks 🙂
Altough, the
T extends Type<unknown, MyScope>
is much better with inference than Type<T, MyScope>
, that's really helpful, thanks 🙂It's impossible for it to use
T["infer"]
because your T
isn't the ArkType type lol
You need T
to be the entire ArkType type, not just the "runtime" type (i.e. Type<number>
and not number
),
I think I see what you mean now actuallyInside I was doing Adapter<T> = SomeWrapper<Type<T, MyScope>["infer"]>
Yeah, it should still be the entire type
The extends
Type<unknown, MyScope>
is still better, I just need to get used to variance rules around unknown