Closed aleclofabbro closed 3 weeks ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
next-safe-action-playground | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 22, 2024 2:07pm |
next-safe-action-website | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 22, 2024 2:07pm |
@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 | null | undefined | any[]
should be added to the condition ?
the original puts together objects, null, and undefined ( S[K] extends object | null | undefined
)
having null and undefined to be pushed to the Prettify<VEList & SchemaErrors<S[K]>>
branch ,
the same for any[]
, being it an object
optionals should not be an issue, as all properties are mapped to be optional, and the S[K] extends
condition checks for the defined prop type, even for optional properties
makes sense ?
@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 null | undefined | any[]
from the NotObject
type, having a schema like this one below, the resulting type of ValidationErrors
isn't correct:
If I instead include those additional types in the NotObject
type, the resulting type of ValidationErrors
is correct:
ha! so that was an existent bug you spotted out while checking my PR ? if so, that's simply great, pow-pow ! lgtm too , any action from me ?
@aleclofabbro Yeah! haha. No actions required from you, gonna merge this soon, thank you for your contribution!
:tada: This PR is included in version 7.9.6 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
returnValidationErrors()
typechecking fails when a property is a primitive-object-intersection type (typical case of branded type).returnValidationErrors()
refers totype SchemaErrors<S>
for typings the purpose oftype SchemaErrors<S>
as is:is to map
S
properties conditionally: if propertyS[K]
isobject | null | undefined
maps toPrettify<VEList & SchemaErrors<S[K]>>
else (propertyS[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 https://github.com/TheEdoRan/next-safe-action/pull/277
re #