'TS2322: Type 'NotRequiredArraySchema<string | undefined>' is not assignable to type 'Ref | Schema<string[] | Using Formik + yup validator

I'm solving this problem. I'm using yup for formik validation. Code for scheme:

const schema = yup.object().shape<Partial<NoteInterface>>({
  noteName: yup.string().required().max(32),
  groupId: yup.number().required(),
  noteText: yup.string().required().max(32),
  noteDuration: yup.string().required().max(32),
  noteTags: yup.array().of(yup.string()),
});

And model code overhere:

export enum cNote {
  noteId = 'noteId',
  groupId = 'groupId',
  noteName = 'noteName',
  noteText = 'noteText',
  noteDuration = 'noteDuration',
  noteCreation = 'noteCreation',
  noteTags = 'noteTags',
}

export interface NoteInterface {
  noteId: string;
  groupId: number;
  noteName: string;
  noteText: string;
  noteDuration: string;
  noteCreation: string;
  noteTags: string[];
}

export const Note = (): NoteInterface => ({
  noteId: '',
  groupId: 0,
  noteName: '',
  noteText: '',
  noteDuration: '',
  noteCreation: '',
  noteTags: [],
});

Everything works fine, except for noteTags which is having this problem:

TS2322: Type 'NotRequiredArraySchema<string | undefined>' is not assignable to type 'Ref | Schema<string[] | undefined> | MixedSchema<string[] | undefined> | undefined'.   Type 'NotRequiredArraySchema<string | undefined>' is not assignable to type 'MixedSchema<string[] | undefined>'. 

thank you for your time



Solution 1:[1]

Have you tried adding .required() to the validator?

const schema = yup.object().shape<Partial<NoteInterface>>({
  noteName: yup.string().required().max(32),
  groupId: yup.number().required(),
  noteText: yup.string().required().max(32),
  noteDuration: yup.string().required().max(32),
  noteTags: yup.array().of(yup.string().required()).required(),
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arturio