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

Throw error for wrong locale type #617

Open
alexfauquette opened this issue Jun 7, 2022 · 0 comments
Open

Throw error for wrong locale type #617

alexfauquette opened this issue Jun 7, 2022 · 0 comments

Comments

@alexfauquette
Copy link
Contributor

Users of mui date pickers use the wrong type when defining their locale because most of the adapters require a string, but date-fns is expecting an object:
mui/mui-x#4598

I propose to add a verification in every constructor such that in development environment then library throw an explicit error message if the type passed is not correct:

constructor({
    locale,
    formats,
  }: { formats?: Partial<DateIOFormats>; locale?: Locale } = {}) {
    if(process.env.NODE_ENV !== 'production'){
	if(locale && typeof locale === 'string'){
  	  throw Error(`date-fns expect \`locale\` to be an object, get a ${typeof locale}`)
        }
    }
    this.locale = locale;
    this.formats = Object.assign({}, defaultFormats, formats);
  }

If it sounds good, I can write the PR

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