dmtrKovalenko / dmtrKovalenko/date-io

Throw error for wrong locale type

Open
#617 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
754
Forks
92
PR merge metrics
No merged PRs in 30d

Description

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:
https://github.com/mui/mui-x/issues/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:

```ts
constructor({
locale,
formats,
}: { formats?: Partial; 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.