Closed devcaeg closed 3 weeks ago
Is it possible that base64ToFile
is causing the problem? The following scheme works in our playground:
import * as v from 'valibot';
const Schema = v.pipe(
v.union([v.string(), v.blob()]),
v.transform((input) =>
typeof input === "string"
? new File([input], "test")
: input
),
v.mimeType(["image/jpeg"])
);
Personally, I would write this schema differently if the transformation and validation is not necessary in every case. Here is an example:
const Schema = v.union([
v.pipe(
v.string(),
v.transform((input) => new File([input], 'image.jpg'))
),
v.pipe(v.blob(), v.mimeType(['image/jpeg'])),
]);
Thank you very much for your response. I have come to the conclusion that the error is caused by Bun
since they are somehow interfering and generating discrepancies between the Blob
, and File
types.
I will close the problem in Valibot
given that it is a problem with the types
in Bun
You can try to replace blob()
with instance(File)
.
Hello,
I am creating a
schema
which has a field that can be astring
or ablob
and usingtransform
fromValibot
I convert them into afile
, the problem is that if in the sameschema
I want to continue applyingvalidators
tofile
,Valibot
is not allowing me to do it.Error:
Type MimeTypeAction<Blob, ["image/jpeg"], undefined> is not assignable to type BaseValidation<File, unknown, BaseIssue<unknown>>
Is there any other way this can be done?