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

ErrorMessage msg should not be a string #1788

Open
kishaningithub opened this issue Sep 1, 2019 · 0 comments
Open

ErrorMessage msg should not be a string #1788

kishaningithub opened this issue Sep 1, 2019 · 0 comments
Labels

Comments

@kishaningithub
Copy link

In my typescript react project, I have integrated yup with react-intl so that error messages can be multiple languages. The way i have configured this is

setLocale({
  mixed: {
    required: () => ({ id: "validation.required" })
  },
  string: {
    email: () => ({ id: "validation.email" })
  },
  number: {
    positive: () => ({ id: "validation.positive" }),
    integer: () => ({ id: "validation.integer" }),
    min: ({ min }) => ({ id: "validation.min", values: { min: min } }),
    max: ({ max }) => ({ id: "validation.max", values: { max: max } }),
    lessThan: ({ less }) => ({
      id: "validation.lessThan",
      values: { less: less }
    })
  }
});

Because of this the error message message now actually is of the form {"id": "validation.positive" } but the following code fails to compile as the "msg" variable is of type "string"

<ErrorMessage 
     name={name}
     render={msg => <FormattedMessage id={msg.id}/>}
 />

My Ugly Temporary Fix

<ErrorMessage 
     name={name}
     render={msg => <FormattedMessage id={JSON.parse(JSON.stringify(msg)).id}/>}
 />

Your environment

Software Version(s)
Formik 1.5.8
React 16.9.0
TypeScript 3.5.3
Browser v10.16.3
npm/Yarn v10.16.3
Operating System Mac os
@stale stale bot added the stale label Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant