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

types: use unknown to better infer types on nested t functions #2018

Conversation

marcalexiei
Copy link
Member

While upgrading to v23 we encounter the same issue described in #2011.

The problem seems caused by any usage in defaultValue, interpolation map and dictionary.
Changing them to unknown should make type infer from nested t work properly.

We have tested this patch on our repository and it seems to be working.

Before

Screenshot 2023-08-09 at 09 38 54

After

Without CustomTypeOptions

Screenshot 2023-08-09 at 09 39 18

With CustomTypeOptions

Screenshot 2023-08-09 at 09 39 11

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • commit message and code follows the Developer's Certification of Origin

@coveralls
Copy link

Coverage Status

coverage: 92.36%. remained the same when pulling b4abeaf on marcalexiei:feature/unexpected-any-on-nested-t-functions into 181dcbd on i18next:master.

Copy link

@koji-- koji-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to see if it would work if it was a string type, but it seems that unknown type would be fine:+1:

Copy link

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran into this issue as well in real world application, and verified that by modifying the type $Dictionary in node_modules/i18next/typescript/helpers.d.ts seems to fix the issue - thanks @marcalexiei!

Are there any work-arounds before this PR is merged and released? Any ways how to overwrite those types with Typescript without using NPM package patches?

Copy link
Member

@pedrodurek pedrodurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems great to me! Thanks!

@marcalexiei
Copy link
Member Author

HI @adrai, could you please merge and release this PR when you have the chance?

@adrai adrai merged commit 5fa7e22 into i18next:master Sep 7, 2023
6 checks passed
@adrai
Copy link
Member

adrai commented Sep 7, 2023

thank you @marcalexiei it's included in v23.5.0

@marcalexiei marcalexiei deleted the feature/unexpected-any-on-nested-t-functions branch September 7, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants