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

Translation function return type DefaultTFuncReturn makes React Native errors #1868

Closed
azuken opened this issue Nov 16, 2022 · 3 comments
Closed

Comments

@azuken
Copy link

azuken commented Nov 16, 2022

馃挜 Regression Report

On React Native, we have some functions which ask for a string | undefined type, for example Alert.alert(), or @react-navigation component attributes.
Since DefaultTFuncReturn returns a string | null value, Typescript raise a type assignation error (TS2322).

TS2322: Type 'DefaultTFuncReturn' is not assignable to type 'string | undefined'.

Can be solved with ?? undefined operator, but it is dirty and very redundant.

Last working version

Worked up to version: 22.0.4

Stopped working in version: 22.0.5

To Reproduce

Steps to reproduce the behavior:

Alert.alert(
      t('home.accountRequiredTitle'),
      t('home.accountRequiredDescription'),
      [
        {
          text: t('home.signIn'),
          onPress: () => navigation.navigate('SignIn')
        },
        {
          text: t('home.signUp'),
          onPress: () => navigation.navigate('SignUp')
        }
      ],
      { cancelable: true }
    );

Expected behavior

No Typescript error.

Your Environment

  • runtime version: node v18
  • i18next version: 22.0.5
  • os: Mac
@adrai
Copy link
Member

adrai commented Nov 16, 2022

This may help: https://www.i18next.com/overview/typescript#argument-of-type-defaulttfuncreturn-is-not-assignable-to-parameter-of-type-xyz

@adrai
Copy link
Member

adrai commented Nov 16, 2022

@azuken
Copy link
Author

azuken commented Nov 16, 2022

Works like a charm! Thanks.

Didn't know such option existed, sorry for the inconvenience!

@azuken azuken closed this as completed Nov 16, 2022
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

2 participants