Pass an array of MIME types to v.mimeType
#748
-
Hi, IMAGES_MIME_TYPES: v.optional(
v.pipe(v.array(v.pipe(v.string(), v.minLength(5))), v.minLength(1)),
["image/png", "image/jpeg"],
), Then I want to create a schema that parses a form submitted to the application with a field containing a file that matches these MIME types. However, I am unable to do this because of the type mismatch: export const imageCreateFormSchema = v.object({
classifiedId: classifiedIdSchema,
imageFile: v.pipe(
v.file(),
v.mimeType(config.IMAGES_MIME_TYPES), // TS2345: Argument of type string[] is not assignable to parameter of type Requirement; Type string is not assignable to type `${string}/${string}`
v.maxSize(config.IMAGES_MAX_SIZE_BYTES)
);
}); I know I could use a regex here like below, but it changes nothing: IMAGES_MIME_TYPES: v.optional(
v.pipe(v.array(v.pipe(v.string(), v.regex(/(^image)(\/)[a-zA-Z0-9_]*/))), v.minLength(1)),
["image/png", "image/jpeg"],
), How can I make the config array compatible with the parameter? |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Jul 27, 2024
Replies: 1 comment 1 reply
-
You have 3 or more options to solve this issue:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sz3lbi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have 3 or more options to solve this issue:
->
v.mimeType(config.IMAGES_MIME_TYPES as `${string}/${string}`[])
string
withtransform
->
v.pipe(v.string(), v.transform((input) => input as `${string}/${string}`))
custom
schema that exactly matches the type->
v.custom<`${string}/${string}`>((input) => typeof input === 'string' && /^image\/[a-z.+-]+$/iu.test(input))