Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

783
Views
Yup validate array of enums in TypeScript

I am trying to validate DTO's using Yup and i can't resolve an issue with checking enums. I have a code similar to the one below:

export enum TestEnum {
  TEST = 0,
  NOT_TEST = 1,
}

export interface SampleDTO {
  testEnum: TestEnum[];
}

export const sampleDtoSchema: SchemaOf<SampleDTO> = yup.object({
  testEnum: yup
    .array(
      yup
        .mixed<TestEnum>()
        .oneOf(Object.values(TestEnum) as TestEnum[])
        .required(),
    )
    .ensure(),
});

And i get this error:

Type 'MixedSchema<TestEnum | undefined, AnyObject, TestEnum>' is not assignable to type 'BaseSchema<Maybe<TestEnum.NOT_TEST>, AnyObject, TestEnum.NOT_TEST>'.
          Types of property '__inputType' are incompatible.
            Type 'TestEnum | undefined' is not assignable to type 'Maybe<TestEnum.NOT_TEST>'.
              Type 'TestEnum.TEST' is not assignable to type 'Maybe<TestEnum.NOT_TEST>'

How it should be done correctly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This might be helpful:

export const sampleDtoSchema: yup.SchemaOf<SampleDTO> = yup.object({
  testEnum: yup
    .array(
      yup
        .mixed()
        .oneOf<TestEnum>(Object.values(TestEnum) as TestEnum[])
        .required()
    )
    .min(1)
    .ensure()
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!