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

Type useMessages() hook using IntlMessages #1452

Open
Tracked by #779
astralarya opened this issue Oct 23, 2024 · 1 comment · May be fixed by #1412
Open
Tracked by #779

Type useMessages() hook using IntlMessages #1452

astralarya opened this issue Oct 23, 2024 · 1 comment · May be fixed by #1412
Labels
enhancement New feature or request

Comments

@astralarya
Copy link

Is your feature request related to a problem? Please describe.

useMessages() hook does not get proper typing after declaring IntlMessages.

For example:

declare global {
  // Use type safe message keys with `next-intl`
  type IntlMessages = {
    foo: {
      bar: string,
      baz: string,
    }
  }
}

function MyComponent() {
  const messages = useMessages();  // expect this to have type IntlMessages
}

Describe the solution you'd like

I would like the useMessages() hook to respect the type provided by IntlMessages

Describe alternatives you've considered

I've considered casting in place every time I invoke the hook, but this is error prone.

@amannn
Copy link
Owner

amannn commented Oct 30, 2024

Sounds good, thanks for the report! This will likely make it into the upcoming v4 release: #1489

amannn added a commit that referenced this issue Oct 30, 2024
…es` (#1489)

If consumers use type-safe `IntlMessages`, these will now be used for
`useMessages` and `getMessages`.

Fixes #1452
@amannn amannn linked a pull request Oct 30, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants