How to integrate generics with extend that need to access a type in scope?
queryValueObject is currently not resolving, and I assume it's because
type()
is creating its own scope. The question is, how can I solve it then?
I also tried it by wrapping it into []
, but this does also not work π€
10 Replies
Haha luckily there is a much better syntax than that π
https://arktype.io/docs/generics#scoped
Although the tuple expression thing was a good intuition, because generics are only legal at the top-level of the scope, we can do something more natural with the alias keys themselves
oh, somehow I missed this part in the docs, although I have read over this today probably already 10 times π¬
Admittedly this part of the docs is a bit less elaborate than most of the rest because I consider both scopes and especially generics to be somewhat advanced features, but all the primary syntax is at least covered now!
I've updated it, but I'm still getting an error that metadata is unresolvable
Type '"metadata"' is not assignable to type '"'metadata' is unresolvableβ"'.ts(2322)
:
If I'm renaming "metadata" to "t" the error changes to Type '"t"' is not assignable to type '"true"'.ts(2322)
read
is nested in an object there, not at the top-level of the scopeThe way you phrase it, sounds like it's a limitation?
Well not really? It wouldn't be sensible to have a generic as the value of a property of an object the same way a Type would be
What values would it allow if you used it for validation?
But if your goal is to allow
namedDocument.read
and the .
access grouping is important, the way to do that is called submodules:
https://arktype.io/docs/scopes#submodules
This would prevent it from accessing aliases from the top-level scope though, since it has to be parsed bottom up.awesome - that is what I need. My goal was to group the types logically to keep it a bit tidy π
Glad you're finding a use case for all the advanced features. Let me know when you run into HKTs π
I have to say I'm quite impressed with how far I have already come without a painful workaround (I say only cyclic references + zod... π ). You did here definitely an outstanding job π