amannn / next-intl

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

Export Href type definition that works for getPathname, redirect & <Link /> params/props #1278

Closed ferares closed 2 months ago

ferares commented 2 months ago

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

I'm struggling to define an Href type that I can then on the return values of createLocalizedPathnamesNavigation (getPathname, Link and redirect)

I've defined it as export type Href = Parameters<typeof getPathname>[0]["href"] which seems to work fine for getPathname but it does not work for either redirect nor the Link component.

Describe the solution you'd like

An importable Href type that's compatible with the href prop of the Link component and the href param of both getPathname and redirect functions.

Describe alternatives you've considered

As of now I'm defining the Href type as Parameters<typeof getPathname>[0]["href"] and using // @ts-expect-error to silence errors when passing values into Link components or redirect calls

amannn commented 2 months ago

The Href type is not intended to be exported. You can likely define a better one based on what is shown in the sitemap docs for localized pathnames that considers the actual pathnames that are available in your app.

I'm going to move this to a discussion since this seems to be more of a usage question.