Union of generics
I've tried to write the following :
But unfortunately it doesn't work because the 2nd parameter accepts a maximum of 3 elements. Is there a way to add arbitrary number of element to a union issued from a generic ?
17 Replies
Tuple expressions are binary so you'd have to nest them.
Oh, I'm gonna try that
It works. It is not very readable though.
Is there any piece of doc to learn how to write functions that take a
Type
as parameter ? I've tried a few things and my function generics could never capture the true type of the given arguments.
This way I could write a function that just build the tuple tower for me ^^Btw maybe you want +:reject
AT allows extra props by default
I want
+:reject
?
you mean to strip additionnal properties ?Yeah what you gonna do on { eq, notEq }
May be fine depending on what you do but generally nt
I'm gonna do specific specs, no prop iteration so it should be fine, but if I can strip extra props I'm all for it
{"+": "delete" }
if you add a key like that to your object it will behave that wayI mean it may be not A|B but A&B, and if you don't handle that you should reject that
What will you do with
?
So like this ?
I don't generally recommend
delete
, consider reject
It's just a question of whether you want the validation to fail or you want the extra keys stripped
For unions I mean
Does delete fail on multibranch union?
Yeah ideally the type would fail to compile if it has
delete
and the union is not discriminatable like in this casePick whatever comes first in my switch ^^ it's an internal API so I the end-dev has basic knowledge of the API.
But yes, you are right, I would prefer the request to be rejected. With
'+': 'reject'
it will throw if there is more prop that the member of the union allow ? That's sick 😍
how can you add that option to a type after the declaration ? Like myArkValidator.options({ reject: true )
onUndeclaredKey
gtg, will be back tonight
.onUndeclaredKey