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 fully type-safe not compatible with context #1333

Closed
jer-sen opened this issue Jun 16, 2021 · 11 comments
Closed

Translation function fully type-safe not compatible with context #1333

jer-sen opened this issue Jun 16, 2021 · 11 comments

Comments

@jer-sen
Copy link

jer-sen commented Jun 16, 2021

馃悰 Bug Report

A resource with context (type_male, type_female) is not allowed with fully TypeScript-safe use.

To Reproduce

{
      "type_male": "homme",
      "type_female": "femme"
}

t('type', { context: 'male' }); // TS error

Expected behavior

No error.

Your Environment

  • i18next@20.3.1
  • react-i18next@11.11.0
@adrai
Copy link
Member

adrai commented Jun 16, 2021

//cc @JCQuintas

@JCQuintas
Copy link
Contributor

JCQuintas commented Jun 16, 2021

This is a limitation of the current type declaration, I can try something later today to see if it can be fixed.

For now you can work around this by using t("type" as keyof CustomTypeOptions['resources']['your_namespace'] , { context: "male" })

@pedrodurek
Copy link
Member

pedrodurek commented Jun 16, 2021

yup, that syntax it's not supported. I'd recommend using this approach instead (for now):

t(`type_${context}` as const);

@stale
Copy link

stale bot commented Jun 23, 2021

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 Jun 23, 2021
@pedrodurek pedrodurek removed the stale label Jun 24, 2021
@stale
Copy link

stale bot commented Jul 1, 2021

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 Jul 1, 2021
@pedrodurek pedrodurek removed the stale label Jul 5, 2021
@stale
Copy link

stale bot commented Jul 12, 2021

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 Jul 12, 2021
@pedrodurek pedrodurek removed the stale label Jul 14, 2021
@stale
Copy link

stale bot commented Jul 21, 2021

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.

@adrai
Copy link
Member

adrai commented Dec 13, 2022

try with i18next v22.4.5

@adrai
Copy link
Member

adrai commented Jun 13, 2023

#1617
#1541

@adrai
Copy link
Member

adrai commented Jun 15, 2023

i18next v23.0.0 will probably not address that yet

@adrai
Copy link
Member

adrai commented Jul 29, 2023

@adrai adrai closed this as completed Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants