-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Localized pathname type error when reached a certain number of objects #726
Comments
Thanks for the report! Just found this, there seems to be a limitation in TypeScript: microsoft/TypeScript#40803. When generating a union based on a type, the number of elements is limited to 25 :-/. You can theoretically disable type checking and allow arbitrary strings for localized pathnames like this: export const { Link, redirect, usePathname, useRouter, getPathname } =
createLocalizedPathnamesNavigation<typeof locales, Record<string, string>>({
locales,
pathnames
}); I'd be curious if there's a better solution in case someone more experienced with TypeScript comes across this. Any chance you could use dynamic params to reduce the number of pathnames (e.g. |
Currently, I'm putting a const lang = useLocale();
const pathname = usePathname();
const router = useRouter();
const params = useParams();
const handleSwitchLanguage = (lang: string) => {
// @ts-expect-error
router.replace({ pathname, params }, { locale: lang });
}; Would be nice if there's another way to get around this 👍 |
Description
I'm implementing localized pathname approach with the doc when I add the language switcher that change the locale of the current page, the
router.replace
method would not accept thepathname
variables that was returned byusePathname()
. Further investigation shows it stops erroring once I reduce the number of routes in my localized pathname object, might be a typescript compiling issue 🤣 Anyway, please take a look and at the recreation repo below on the branch "next-intl-issue". If you add another route thepathname
innavigation.ts
typescript will error out inSwitcher.tsx
. In this repo the threshold is 26, but in my other project it's 24, that website has a dynamic route in the pathname.Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://github.com/m4rvelous252/next-demo/tree/next-intl-issue
Reproduction description
Steps to reproduce:
pathnames
innavigation.ts
Switcher.tsx
Expected behaviour
Would be nice if typescript behave correctly here
The text was updated successfully, but these errors were encountered: