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

[next-i18next] 9.0.8 -> 9.1.0: Type 'unknown' is not assignable to type 'never'. #869

Closed
Zerebokep opened this issue Nov 2, 2022 · 7 comments

Comments

@Zerebokep
Copy link

My toast() calls complain about the type now, especially when using next-i18next's t():

toast(t('test.test'))

casting to string works, but isn't that pretty. Any chance to get the old behaviour back or was this a typescript optimization?

Argument of type 'ToastContent<never>' is not assignable to parameter of type 'ToastContent<unknown>'.
  Type '(props: ToastContentProps<never>) => ReactNode' is not assignable to type 'ToastContent<unknown>'.
    Type '(props: ToastContentProps<never>) => ReactNode' is not assignable to type '(props: ToastContentProps<unknown>) => ReactNode'.
      Types of parameters 'props' and 'props' are incompatible.
        Type 'ToastContentProps<unknown>' is not assignable to type 'ToastContentProps<never>'.
          Type 'unknown' is not assignable to type 'never'.
@fkhadra
Copy link
Owner

fkhadra commented Nov 2, 2022

Hey @Zerebokep, I'm investigating the issue. It's really strange though.

// OK
 const tt = t("foo")
 toast(tt)

// NOK
toast(t("foo"))

// OK
function x(){ return 'hello' }
toast(x())

Anyway I'll push a fix :)

@fkhadra
Copy link
Owner

fkhadra commented Nov 2, 2022

@Zerebokep while I figure out the proper fix you can do write toast<void>(t("foo")); instead of using type assertion.

@fkhadra fkhadra changed the title 9.0.8 -> 9.1.0: Type 'unknown' is not assignable to type 'never'. [next-i18next] 9.0.8 -> 9.1.0: Type 'unknown' is not assignable to type 'never'. Nov 2, 2022
@fkhadra
Copy link
Owner

fkhadra commented Nov 2, 2022

So, after checking the source of next-i18next, they added extends infer A ? A : never as a workaround for this issue i18next/react-i18next#1222.

Still investigating what would be a proper fix and if it needs to be fixed.

/**
 * Due to a limitation/bug on typescript 4.1 (https://github.com/microsoft/TypeScript/issues/41406), we added
 * "extends infer A ? A : never" in a few places to suppress the error "Type instantiation is excessively deep and possibly infinite."
 * on cases where users have more than 22 namespaces. Once the issue is fixed, we can remove all instances of the workaround used.
 *
 * Reference of the bug reported: https://github.com/i18next/react-i18next/issues/1222
 */

@Zerebokep
Copy link
Author

Really appreciate your effort, you rock.

@raulcrisan
Copy link

Hey guys, any news regarding this issue? When will be available a version with this fix?

@Zerebokep
Copy link
Author

next-i18next v13 seems to fix this issue.

@fkhadra
Copy link
Owner

fkhadra commented Nov 24, 2022

Thanks for the update. I'll close the issue

@fkhadra fkhadra closed this as completed Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants