TypeScript integration: how to use ArraySchema properly?
Author: rockychordteaCreated Nov 22, 2022Updated Oct 15, 2025
I didn't find any documentation on ArraySchema usage.
Specifically, it's not clear what its type parameters mean.
declare class ArraySchema<TIn extends any[] | null | undefined, TContext, TDefault = undefined, TFlags extends Flags = ''> ...With just a single array-type parameter it doesn't work for obvious reason: the second parameter is required:
const foo: yup.ArraySchema<number[]> = yup.array().of(yup.number().defined()).defined()triggering an error:
Generic type 'ArraySchema<TIn, TContext, TDefault, TFlags>' requires between 2 and 4 type arguments.However, passing any as the second parameter doesn't make it work either:
const foo: yup.ArraySchema<number[], any> = yup.array().of(yup.number().defined()).defined()and fails with this error:
Type 'ArraySchema<number[], AnyObject, "", "">' is not assignable to type 'ArraySchema<number[], any, undefined, "">'.
Type '""' is not assignable to type 'undefined'.Guessing further, after sett the third parameter to any removes error messages:
const foo: yup.ArraySchema<number[], any, any> = yup.array().of(yup.number().defined()).defined()I wonder, what is the correct way to use this and what is the meaning of the parameters?
Version: 1.0.0-beta.8
Source: jquense/yup