Skip to content

Pass an array of MIME types to v.mimeType #748

Answered by fabian-hiller
sz3lbi asked this question in Q&A
Discussion options

You must be logged in to vote

You have 3 or more options to solve this issue:

  1. Use type casting and just tell TypeScript that the types match
    -> v.mimeType(config.IMAGES_MIME_TYPES as `${string}/${string}`[])
  2. Transform the output type of string with transform
    -> v.pipe(v.string(), v.transform((input) => input as `${string}/${string}`))
  3. Create a custom schema that exactly matches the type
    -> v.custom<`${string}/${string}`>((input) => typeof input === 'string' && /^image\/[a-z.+-]+$/iu.test(input))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sz3lbi
Comment options

Answer selected by sz3lbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants