Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Typings: array.ensure() should not produce undefined #2180

Open
denis-pakhorukov opened this issue Mar 6, 2024 · 0 comments
Open

Comments

@denis-pakhorukov
Copy link

Describe the bug
According to the documentation, array.ensure() sets the default to [] and transforms null and undefined values to an empty array. However, the typings imply that undefined is still a possible value.

To Reproduce

import * as Yup from "yup";

const userSchema = Yup.object().shape({
  array1: Yup.array().of(Yup.string().required()),
  array2: Yup.array().of(Yup.string().required()).default([]),
  array3: Yup.array().of(Yup.string().required()).ensure(),
});

type User = Yup.InferType<typeof userSchema>;

Actual behavior

type User = {
    array1?: string[] | undefined;
    array2: string[];
    array3?: string[] | undefined;
}

Expected behavior

type User = {
    array1?: string[] | undefined;
    array2: string[];
    array3: string[];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant