Skip to content

trim, lowercase, uppercase: tries to do this even if there is no string and gets a TypeError #2303

@fir4tozden

Description

@fir4tozden

I previously opened an issue for this, but it was ignored. If trim(), lowercase(), or uppercase() is used in a string(), a TypeError error is thrown during validation if the incoming data is not a string.

Everything here is as it should be ✅

Image

Everything here is as it should be ✅

Image

But it wasn't supposed to be like this ❌

Image

Temporary solution 🔧

We can use the transform() for now. However, this doesn't mean I should ignore the problem above.

import * as Yup from "yup";

const schema = Yup.string()
  .transform(property => typeof property === "string" ? property.trim() : property)
  .min(3);

console.log(schema.validateSync({}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions