-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(validation-errors): type inference for branded, nullable, optional and array types #284
fix(validation-errors): type inference for branded, nullable, optional and array types #284
Conversation
…emaerrors<s>): brand primitives flip `type SchemaErrors<S>` mapping conditional to eagerly detect branded (object-intersected) primitives amend PR#277
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@aleclofabbro is attempting to deploy a commit to the Edoardo Ranghieri's projects Team on Vercel. A member of the Team first needs to authorize it. |
@aleclofabbro updated code to fix inference for optionals, nullables and arrays too. Please check it out, lgtm so I think it can be merged. |
@TheEdoRan are you sure |
@aleclofabbro yep, while I was working on this I found out that arrays, nullables and optionals weren't typed as expected. In fact, if I remove If I instead include those additional types in the |
ha! so that was an existent bug you spotted out while checking my PR ? if so, that's simply great, pow-pow ! |
@aleclofabbro Yeah! haha. No actions required from you, gonna merge this soon, thank you for your contribution! |
🎉 This PR is included in version 7.9.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
returnValidationErrors()
typechecking fails when a property is a primitive-object-intersection type (typical case of branded type).returnValidationErrors()
refers totype SchemaErrors<S>
for typingsthe purpose of
type SchemaErrors<S>
as is:is to map
S
properties conditionally:if property
S[K]
isobject | null | undefined
maps toPrettify<VEList & SchemaErrors<S[K]>>
else (property
S[K]
is primitive) maps toVEList
the issue arises when property
S[K]
is a branded primitive type.Branded primitive types are typically an intersection of a primitive with an object holding the brand
(e.g.
type email = string & { [k in brand_prop_type]: unique symbol }
)type SchemaErrors<S>
mapping condition considers branded-primitive-types as object, mapping them incorrectly, and finally leading toreturnValidationErrors()
type errorsProposed changes
the issue is resolved by simply reversing the condition:
this way any primitive - even when intersected - is eagerly catched and properly managed, keeping logic unaltered
Related issue(s) or discussion(s)
This is an amend of a previous (closed) PR
#277
re #