question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: must be a `string` type, but the final value was

See original GitHub issue

Describe the bug I have a React App which has Formik and use Yup to create the Validation Schema. I recently updated Yup from 0.29.1 -> 0.32.8. I am unaware of any breaking changes since the release page does not contain any change log. The problem is with the react-select component. The initial validation which is triggered by clicking Submit button shows properly “Please select city” (from below codesandbox example). Upon selecting a item from the list it displays error from the validator as "city must be a string type, but the final value was { "label", "value"} "

Error seems to be when updating to Yup version higher than 0.29.1.

To Reproduce

Try this sandbox which has Yup version to 0.32.8.

Demo Codesandbox

Expected behavior

From the above codesandbox try downgrading to Yup version 0.29.1 which is the expected output. The form has to submit without errors.

Platform (please complete the following information):

  • Browser: All browsers
  • For libraries versions please refer the above codesandbox

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
meetajhucommented, Dec 30, 2020

@jquense Thanks for the quick response. Instead of recreating the old behavior how do you expect me to write the schema for the react-select input?

const schema = Yup.object().shape({
      city: Yup.object().shape({
        label: Yup.string().required("Is required"), 
        value: Yup.string().required("Is required")
      })
 })
2reactions
jquensecommented, Dec 29, 2020

see: https://github.com/jquense/yup/blob/master/CHANGELOG.md#breaking-changes-1 plain objects are no longer automatically cast to strings. Judging from your example this is now uncovering a bug you have, assuming you don’t want the value of city to be '[object Object]'

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formik & yup form validation not working as expected with ...
When I clear my select field I get an ERROR - 'category must be a string type, but the final value was: null...
Read more >
Formik & yup form validation not working as expected ...
When I clear my select field I get an ERROR - 'category must be a string type, but the final value was: null...
Read more >
Validating a Tree in Yup with Typescript - Mark Lilback
I've been working in Typescript lately using Yup for validating my objects.
Read more >
Using yup and typescript for typesafe select validation
Typescript automatically infers the string type for our array, which is actually correct because our variable might be const but adding new values...
Read more >
Validating Optional Objects with Yup - Object Partners
The Yup object validation library provides a lot of tools, but how do we ... with the `object` // type, we have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found