subtypes available on scope in 2.0.0-beta.6

I have a scope defined but not seeing subtypes available
No description
21 Replies
PIat
PIat5w ago
Hello! What exactly are you trying to achieve?
frolic
frolic5w ago
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
No description
frolic
frolic5w ago
and according to docs, I should be able to reference types within scope like in my first screenshot: https://arktype.io/reference/scopes/
ArkType
Scopes
TypeScript's 1:1 validator, optimized from editor to runtime
PIat
PIat5w ago
So you want to reuse the type from the scope inside of a derived type?
frolic
frolic5w ago
none of the types defined in the scope appear to be available on types object
frolic
frolic5w ago
simplified example
No description
PIat
PIat5w ago
The way you'd achieve that is by doing
const derivedType = types.type({
number: 'Bytecode'
})
const derivedType = types.type({
number: 'Bytecode'
})
here example.type()
frolic
frolic5w ago
ahh so docs are out of date? oh I see now, I missed .export() at the end of scope()
PIat
PIat5w ago
The docs are WIP and don't mention this functionality yet
frolic
frolic5w ago
.export() resolved it
PIat
PIat5w ago
Actually they do AFAIK, if you want to extend the scope, you instantiate it without .export?
frolic
frolic5w ago
no clue but for my needs, its statically defined, don't need to extend it
ssalbdivad
ssalbdivad5w ago
@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 pattern
PIat
PIat5w ago
Thank you a lot for the explanation! It sounded like straight out of the documentation 😁
ssalbdivad
ssalbdivad5w ago
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
Want results from more Discord servers?
Add your server