vine icon indicating copy to clipboard operation
vine copied to clipboard

Vine Enum with nullable

Open kevinmelo opened this issue 6 months ago • 2 comments

Package version

latest

Describe the bug

When i validate using VineJs and one of the keys is a enum but can be null it's give me de following error:

TypeError: Cannot convert undefined or null to object at Function.values (<anonymous>) at _VineNativeEnum

with the following json:

{
   "object": "my_object",
   "entry": [
       {
           "id": "0",
           "time": 1723073445,
           "changes": [
               {
                   "field": "any_field",
                   "value": {
                       "event": "APPROVED",
                       "message_template_id": 12345678,
                       "message_template_name": "my_message_template",
                       "message_template_language": "pt-BR",
                       "reason": null
                   }
               }
           ]
       }
   ]
}

The Complete vine schema:

export default vine.compile(
    vine.object({
        object: vine.string(),
        entry: vine.array(
            vine.object({
                id: vine.string(),
                time: vine.number(),
                changes: vine.array(
                    vine.object({
                        field: vine.string(),
                        value: vine.object({
                            event: vine.enum(OTHER_ENUM),
                            message_template_id: vine.number(),
                            message_template_name: vine.string(),
                            message_template_language: vine.string(),
                            reason: vine.enum(MY_ENUM).nullable(),
                        }),
                    })
                ),
            })
        ),
    })
)

Where the erro occurs reason: vine.enum(MY_ENUM).nullable(),

Reproduction repo

No response

kevinmelo avatar Aug 08 '24 00:08 kevinmelo