subtypes available on scope in 2.0.0-beta.6
I have a scope defined but not seeing subtypes available
21 Replies
Hello! What exactly are you trying to achieve?
I previously had types defined as discrete type objects and was passing around references within each type, but @ssalbdivad recommended moving it to a scope where everything is inlined
and according to docs, I should be able to reference types within scope like in my first screenshot:
https://arktype.io/reference/scopes/
So you want to reuse the type from the scope inside of a derived type?
none of the types defined in the scope appear to be available on
types
objectsimplified example
The way you'd achieve that is by doing
here
example.type()
ahh so docs are out of date?
oh I see now, I missed
.export()
at the end of scope()
The docs are WIP and don't mention this functionality yet
.export()
resolved itActually they do
AFAIK, if you want to extend the scope, you instantiate it without
.export
?no clue
but for my needs, its statically defined, don't need to extend it
@PIat @frolic A scope is just like a scope in code- it's a resolution space where you can define types, generics, etc.
type
is a method of a Scope
.
Another method is called export
. That method takes all the public names in your scope, and puts them in an object called a Module
so you can access them directly
A lot of the time, if you won't need to create additional types in your scope as @PIat said, you can just export right away.
In the next release, I'm actually adding a type.module
sugar that just creates the scope and immediately exports it since it's such a common patternThank you a lot for the explanation! It sounded like straight out of the documentation 😁
Yeah I think my perfectionism gets in the way bit with docs. Some of it I just threw up there, but the stuff I consider "done" I try to think about too much