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

Issue with TS 4.1 example & specific translations keys #1215

Closed
Thanaen opened this issue Dec 8, 2020 · 11 comments
Closed

Issue with TS 4.1 example & specific translations keys #1215

Thanaen opened this issue Dec 8, 2020 · 11 comments

Comments

@Thanaen
Copy link

Thanaen commented Dec 8, 2020

馃悰 Bug Report

Hi !
I've tried to apply the new TS 4.1 example, but it seems to break when a there is a key named "keys" in the translations file, like this:

en.json

{
  "home": {
    "menu": "I work fine",
    "keys": "I am not known by TypeScript :("
  }
}

To Reproduce

Here is a simple repo I used to reproduce this issue: https://github.com/Thanaen/repro-react-i18n-ts-bug
Simply clone it, run 'yarn' then 'yarn lint' or 'yarn start' !

Expected behavior

I should be able to call t('home.keys') without any linting or typescript errors.

Your Environment

  • runtime version: Firefox 83 & Chrome 87
  • i18next version: ^0.13.2
  • os: Windows
  • react-i18next: ^11.8.0
@Thanaen
Copy link
Author

Thanaen commented Dec 8, 2020

@pedrodurek Mentioning you because @jamuhl suggested it, and because you merged a TypeScript 4.1 related pull request recently!

@pedrodurek
Copy link
Member

pedrodurek commented Dec 8, 2020

Hey @Thanaen, good catch! it turns out that in order to make it work with arrays like this:

{
  list: [{
    title: 'title1' 
  }, {
    title: 'title2' 
  }]
}

I'm omitting all props from Array (https://github.com/i18next/react-i18next/blob/master/src/ts4.1/index.d.ts#L45), and the key "keys" is one of them.
Thanks from flagging that! I'll see what I can do. In the meantime, I'd recommend using a different key for now.

@Thanaen
Copy link
Author

Thanaen commented Dec 9, 2020

Okay, @pedrodurek ! I'll try not to use this key for now ! 馃憤
Thank you for your quick response. :)

@stale
Copy link

stale bot commented Dec 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 16, 2020
@pedrodurek
Copy link
Member

pedrodurek commented Dec 16, 2020

@jamuhl could you change the label to bug and typescript? I still need to work on this one. Thanks!

@stale stale bot removed the stale label Dec 16, 2020
@jamuhl jamuhl added bug and removed bug labels Dec 17, 2020
pedrodurek pushed a commit to pedrodurek/react-i18next that referenced this issue Dec 26, 2020
pedrodurek added a commit to pedrodurek/react-i18next that referenced this issue Dec 26, 2020
@pedrodurek
Copy link
Member

pedrodurek commented Dec 28, 2020

Hey @Thanaen, it should be fixed now! 聽馃檶
v11.8.5

@daniellwdb
Copy link

daniellwdb commented Jan 2, 2021

Once microsoft/TypeScript#32063 becomes a thing, we would be able to infer the object keys for interpolation as well https://gist.github.com/pandaniell/a7000d31ec89436f4d4e4cf68ea88f0b
By creating a TypeScript Language Service plugin you could have live feedback even in JS projects with TS as dev dep by only providing a path to the translations in the tsconfig, been experimenting with that here (see gif in README) but it is not easy

@pedrodurek
Copy link
Member

Niceee, thanks for sharing it @pandaniell

@pedrodurek
Copy link
Member

@jamuhl could you close this task? Thanks!

@jamuhl jamuhl closed this as completed Jan 5, 2021
@Thanaen
Copy link
Author

Thanaen commented Jan 7, 2021

Hi ! It took me a long time to answer, but thank you very much @pedrodurek for your work. :)

@pedrodurek
Copy link
Member

@Thanaen No problem! Thank you too! 馃檶

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

5 participants