-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
t
from getTranslations({locale, namespace})
can`t receive any arguments when not using typed messages
#625
Comments
To be able to look into this, a reproduction would be required. Maybe your IDE uses another version of TypeScript that reports a false positive (instead of the local one)? This repo also uses What I did notice so far is that |
I cloned your example and compared the package versions with my project. It's all the same. I don't understand why this error occurs in my project... An IDE should not affect the build process. Build error still appear in terminal.
When next-intl version set to 3.0.0-rc.9, there are no any error. |
i have update to 3.0.1 face this issue too export async function generateMetadata({ params: { locale } }: PageProps) {
const t = await getTranslations({ locale, namespace: 'IndexPage' });
return {
title: t('title'),
};
} namespace: 'IndexPage' can not show typings useTranslations() works fine. |
Ah, I think I found the error! The error happens when you don't use the TypeScript integration of As a temporary workaround, you can define this in a file like // Temporary workaround for https://github.com/amannn/next-intl/issues/625
type Messages = any
declare interface IntlMessages extends Messages {}
I'll look into a proper fix. Thanks for the report! |
t
from getTranslations({locale, namespace})
can`t receive any arguments when not using typed messages
// Use type safe message keys with `next-intl`
type Messages = typeof import('./messages/en.json');
declare interface IntlMessages extends Messages {} 3.0.2 also has this issue. |
Yep, I noticed too that somehow TypeScript doesn't provide autocomplete for this case. However, errors are correctly detected. Note that this only affects the object form, not when calling If some TypeScript wizard would like to have a look, I'd really appreciate it! |
haha, Expect ts experts to help :) have no idea |
I trying to do this. but it does not find my string and my string is right. const local = "sv" // MANUALLY SPECIFIED LOCALE error: IntlError: MISSING_MESSAGE: Could not resolve I use |
Description
When calling t from getTranslations with correct argument, the IDE shows on t argument this TypeScript error: TS2345: An argument of type string is not assigned to a parameter of type never. This error appears also when is building.
This error appears in next-intl starting from version 3.0.0-rc.10. In version 3.0.1, this error is also present.
IDE show this type of t:
Sample code with this error:
I am using IDE Webstorm 2023.2.5. TypeScript version 5.2.2. Next.js version 14.0.2.
CodeSandbox reproduction do not show this error. This error is in IDE with TypeScript and building.
Expected behaviour
I want there to be no TypeScript error: TS2345: An argument of type string is not assigned to a parameter of type never.
The text was updated successfully, but these errors were encountered: