-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
Strict typing of global formats #1112
Comments
Hey, I think I might be interested in implementing this. I was thinking of setting it close to their type definition for messages, like: import en from './messages/en.json'
import formats from '~/i18/request.ts'
type Messages = typeof en;
declare global {
// Use type safe message keys with `next-intl`
interface IntlMessages extends Messages {}
type IntlFormats = typeof formats
} Something quite like that. Do you think that this api could work? Then the user would only need to do this once and any changes to their format object would reflect the type here |
If you're up for it, that would be 💯! As far as I know, it has to be an interface in order to work. Interfaces have this special ability in TypeScript that declarations can be merged when re-declared. Based on the implementation for the messages, I think these are the required steps:
Now, when a consumer installs the package, the Maybe with a condition we could still ensure that only a string is accepted for a local format in case no Let me know in case I can help with something! 🙌 |
Thanks. Will look into it when I have some free time. |
Is your feature request related to a problem? Please describe.
Similar to how we support strict typing of messages, we could provide strict typing for formats.
Describe the solution you'd like
Allow the user to define
IntlFormats
to enable this.Describe alternatives you've considered
Not providing strict formats.
The text was updated successfully, but these errors were encountered: