`trim`, `lowercase`, `uppercase`: tries to do this even if there is no string and gets a TypeError
Author: fir4tozdenCreated Aug 4, 2025Updated Mar 15, 2026
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 ✅
Everything here is as it should be ✅
But it wasn't supposed to be like this ❌
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({}));Source: jquense/yup