Need help with typing scope output properly
I've got one crazy idea to declare types as scopes to access validators independently
4 Replies
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
You can see it in action via the link
However, I have one problem: a typescript error
Wait, let me rewrite this example a little
Ok, here is the initial idea:
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
I'd call it lazy validation
You can create a class w/o any config, ok?
But if you pass something to it, it will be validated
Yet you're not required to do that
Later on, when using this class, if at some point a property will be requested...
then it WILL be checked against the initial schema
and it will become required if it was required by the intial schema
The
foo
getter does exactly this:
Note that i"m using here the original validator from the scope
Now
I want to automate this process 🙂
So I add a sort of an universal getter which can validate things
Damn
LOL, ok, nevermind. Ignore me. Hahaha
I added the return type wrong
If I remove Config[K]
it works by itself. So it's properly inferred
But out of interest, what would be the correct return type in this case?
If we try to not use functions w/o direct returns
I feel like deleting this topic. And rewriting it from scratch LOL