A
arktype4mo ago
frolic

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
PIat4mo ago
Hello! What exactly are you trying to achieve?
frolic
frolicOP4mo 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
frolicOP4mo 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
PIat4mo ago
So you want to reuse the type from the scope inside of a derived type?
frolic
frolicOP4mo ago
none of the types defined in the scope appear to be available on types object
frolic
frolicOP4mo ago
simplified example
No description
PIat
PIat4mo 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
frolicOP4mo ago
ahh so docs are out of date? oh I see now, I missed .export() at the end of scope()
PIat
PIat4mo ago
The docs are WIP and don't mention this functionality yet
frolic
frolicOP4mo ago
.export() resolved it
PIat
PIat4mo ago
Actually they do AFAIK, if you want to extend the scope, you instantiate it without .export?
frolic
frolicOP4mo ago
no clue but for my needs, its statically defined, don't need to extend it
ssalbdivad
ssalbdivad4mo 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
PIat4mo ago
Thank you a lot for the explanation! It sounded like straight out of the documentation 😁
ssalbdivad
ssalbdivad4mo 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
PIat
PIat4mo ago
Perfectionism is so worth it when you do get to actually finish the project
ssalbdivad
ssalbdivad4mo ago
Yeah it's complicated, I would not have what I have without being obsessive and perfectionistic but it's not helping anyone if I'm not publishing things that would be improvements because I'm working on bigger improvements
PIat
PIat4mo ago
I think it does help It's the principle of potential and actual value. When a person learns many things, it's of no substance to the world yet. But as soon as they start utilizing the knowledge, it will be of much more use than if they had started working earlier, since their potential was bigger and all of a sudden exploded into merit. Similar thing here — while you could be documenting all the features, it would take a lot of time and most importantly mental strain. The development would be slower. But now you're moving at your proper fast pace, and at the point when it'll all be done, then you'll have documentation which you're 100% sure of and it'll be a 💥
ssalbdivad
ssalbdivad4mo ago
Yes I agree with all of that. I just mean in cases like the one I just explained, I'm already taking the time to answer questions explaining how stable features work, there wouldn't be any downside to just copy pasting that answer to docs TBH
PIat
PIat4mo ago
True! Do it! It'll also feel good 😋
ssalbdivad
ssalbdivad4mo ago
You know, I meant it hypothetically, but I already have a scope page. I guess I will 😅
Want results from more Discord servers?
Add your server