amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.61k stars 236 forks source link

Type Safe hooks and functions #1497

Closed chertik77 closed 3 weeks ago

chertik77 commented 3 weeks ago

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

Yes, I would like to have typed hooks or functions through declarations or out of the box.

const locale = useLocale() as Locale
const locale = (await getLocale()) as Locale

I have predefined type for my locales and I dont want to type this hook and function again and again.

export const routing = defineRouting({
  locales: ['uk', 'en'],
  defaultLocale: 'uk'
})

export type Locale = (typeof routing.locales)[number]

Describe the solution you'd like

Be able to add declaration, like for messages. Or infer types from routing.locales and type them inside of the library.

Describe alternatives you've considered

-

chertik77 commented 3 weeks ago

Sorry, I didn't see your pr about strict types