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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not existing context not detected as type error if covered by string union #1743

Closed
stefan-schweiger opened this issue Apr 11, 2024 · 2 comments
Assignees

Comments

@stefan-schweiger
Copy link

馃悰 Bug Report

When you use a string union as the context parameter it's possible to supply values for which a context does not exist and it does not result in an error. If you just use the plain string value or a const it works.

To Reproduce

A minimal reproducible example.

{
  "translation": {
    "testContext1_Test1": "EN: Context1 Test1",
    "testContext1_Test2": "EN: Context1 Test2",
  },
}
const App = () => {
  const { t } = useTranslation('translation');

  return (
    <div>
      <p>
        {t('testContext1', { context: 'Test1' as 'Test1' | 'Test2' | 'Test3' })}
      </p>
      <p>{t('testContext1', { context: 'Test2' })}</p>
      <p>{t('testContext1', { context: 'Test2' as const })}</p>
      <p>
        {t('testContext1', { context: 'Test3' as 'Test1' | 'Test2' | 'Test3' })}
      </p>
      {/* Error: Type '{ context: "Test3"; }' is not assignable to type 'string' */}
      <p>{t('testContext1', { context: 'Test3' })}</p>
      {/* Error: Type '{ context: "Test3"; }' is not assignable to type 'string' */}
      <p>{t('testContext1', { context: 'Test3' as const })}</p>
    </div>
  );
};

Expected behavior

String unions should be correctly detected as errors if they have cases which are not covered by the context.

Your Environment

  • runtime version: i.e. node v14, deno, browser xy
  • i18next version: i.e. 19.5.3
  • os: Mac, Windows, Linux
  • any other relevant information
@marcalexiei
Copy link
Member

This issue is an upstream issue, so it should be handled in i18next not react-i18next.
@adrai can the issue be moved there or it needs to be closed and reopened there?

@stefan-schweiger
Copy link
Author

Thanks, I have reopened the issue in i18next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants