Typescript tips
TypeScript tips & troubleshooting
Section titled “TypeScript tips & troubleshooting”Ensure AppMessages matches your next-intl message shape
Section titled “Ensure AppMessages matches your next-intl message shape”The factory createUseTranslatedToast<AppMessages>() should receive the same shape you use with next-intl types. That makes key strongly typed and improves DX in editors.
Common type errors
Section titled “Common type errors”keynot assignable: Make sure yourAppMessagesgeneric matches the actual messages shape. If you use nested namespaces, ensure the type exposes nested keys.- Translator method not found at runtime: The provider expects a real
translatorfromnext-intl— not a lightweight mock. For tests you can usecreateTranslator({ locale: 'en', messages }).
notificationsRoot mismatches
Section titled “notificationsRoot mismatches”If you pass a notificationsRoot that isn’t present in your messages type, TypeScript will complain. Either update your messages type or omit notificationsRoot and include the full namespaced key in key values.