Have a bug after migrating from beta.12 to beta.14 #1036
-
import * as v from 'valibot';
export const ResultResultSchema = v.object({
id: v.union([v.string(), v.number()], 'id must be string or number'),
result: v.union(
[
v.string(),
v.number(),
v.boolean(),
v.array(v.unknown()),
v.object({}),
],
'result must be one of: string, number, array, boolean or object'
),
error: v.undefined('error must be undefined'),
}); Data for validation const data = {
id: "0194a777-a4d4-2d2b-55fb-f50761ca7276",
result: "Ok"
} validation the data const result = v.safeParse(ResultResultSchema, data); in the 12th beta, everything worked as expected - the validation result was positive validation result {
"typed": false,
"success": false,
"output": {
"id": "0194a777-a4d4-2d2b-55fb-f50761ca7276",
"result": "Ok"
},
"issues": [
{
"kind": "schema",
"type": "union",
"input": {
"id": "0194a777-a4d4-2d2b-55fb-f50761ca7276",
"result": "Ok"
},
"expected": "Object",
"received": "Object",
"message": "Invalid type: Expected Object but received Object",
"issues": [
{
"kind": "schema",
"type": "object",
"expected": "error",
"received": "undefined",
"message": "Invalid key: Expected 'error' but received undefined",
"path": [
{
"type": "object",
"origin": "key",
"input": {
"id": "0194a777-a4d4-2d2b-55fb-f50761ca7276",
"result": "Ok"
},
"key": "error"
}
]
},
{
"kind": "schema",
"type": "undefined",
"input": "Ok",
"expected": "undefined",
"received": "Ok",
"message": "Invalid type: Expected undefined but received `Ok`",
"path": [
{
"type": "object",
"origin": "value",
"input": {
"id": "0194a777-a4d4-2d2b-55fb-f50761ca7276",
"result": "Ok"
},
"key": "result",
"value": "Ok"
}
]
},
{
"kind": "schema",
"type": "object",
"expected": "error",
"received": "undefined",
"message": "Invalid key: Expected 'error' but received undefined",
"path": [
{
"type": "object",
"origin": "key",
"input": {
"id": "0194a777-a4d4-2d2b-55fb-f50761ca7276",
"result": "Ok"
},
"key": "error"
}
]
}
]
}
]
} |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Jan 27, 2025
Replies: 1 comment 3 replies
-
The "error" property of the object is required but missing in |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have a look at this playground. Here is the schema: