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

Statically typed links for Link returned from createSharedPathnamesNavigation #396

Open
amannn opened this issue Jul 12, 2023 · 4 comments
Labels
area: ergonomics contributions welcome Good for people looking to contribute enhancement New feature or request

Comments

@amannn
Copy link
Owner

amannn commented Jul 12, 2023

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

Next.js now supports statically typed links, we should support this too in Link that is returned from createSharedPathnamesNavigation. Also rewrites/redirects should be supported now (needs to be validated).

Note that the Link that is returned from createLocalizedPathnamesNavigation is already statically typed, this issue only applies to createSharedPathnamesNavigation.

Describe the solution you'd like

Compose existing types from Next.js for static typing to work

Describe alternatives you've considered

Leaving the routes untyped as string.

@amannn amannn added enhancement New feature or request unconfirmed Needs triage. contributions welcome Good for people looking to contribute and removed unconfirmed Needs triage. labels Jul 12, 2023
@amannn amannn changed the title Statically types links for next-intl/link Statically typed links for next-intl/link Jul 12, 2023
@amannn amannn changed the title Statically typed links for next-intl/link Statically typed links with next-intl/link Jul 12, 2023
@Aperrix
Copy link

Aperrix commented Aug 12, 2023

up pls ?

@amannn
Copy link
Owner Author

amannn commented Aug 22, 2023

I'm currently working on pathname localization in #426 (see details in #402). This will introduce statically typed links when using this feature.

However it would still be cool if we can statically validate links when not using localized pathnames, so I'll leave this issue open for now.

@tacomanator
Copy link
Contributor

tacomanator commented Jan 16, 2024

Since the two issues referenced are closed, can I safely assume localized routes are typed checked? I could not find relevant docs, but so far I'm having no luck and want to make sure I'm not trying to make something work that simply wont.

typedRoutes is enabled in next config, and using the <Link /> component from createSharedPathnamesNavigation as described in the docs:

import { locales } from "@/i18n";
import { createSharedPathnamesNavigation } from "next-intl/navigation";

export const localePrefix = "always"; // Default

export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales, localePrefix });

but the Link exported from here does not give me type errors bad urls:

import { Link } from "@/navigation";

export default function Index() {
  return (<Link href="/invalidpath">invalid path</Link>); // no type error
}

@amannn amannn changed the title Statically typed links with next-intl/link Statically typed links for Link returned from createSharedPathnamesNavigation Jan 16, 2024
@amannn
Copy link
Owner Author

amannn commented Jan 16, 2024

@tacomanator createSharedPathnamesNavigation currently doesn't provide static typechecking, only createLocalizedPathnamesNavigation does. I've updated the initial feature request accordingly now.

Contributions are welcome for this feature btw., in case someone is interested in looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ergonomics contributions welcome Good for people looking to contribute enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants