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

[Typescript] Wrong key type when using context on TS5+ #2242

Closed
AlexKrupko opened this issue Oct 4, 2024 · 3 comments · Fixed by #2243 · May be fixed by respencer/ChurchCRM#40 or Vishesh7797/open-webui#5
Closed

[Typescript] Wrong key type when using context on TS5+ #2242

AlexKrupko opened this issue Oct 4, 2024 · 3 comments · Fixed by #2243 · May be fixed by respencer/ChurchCRM#40 or Vishesh7797/open-webui#5

Comments

@AlexKrupko
Copy link

AlexKrupko commented Oct 4, 2024

🐛 Bug Report

Typescript 5+ infers wrong keys when using keys with context.
On TS4, everything works as expected.
Screenshot 2024-10-05 at 00 15 22

To Reproduce

import i18next from 'i18next';

const resources = {
    translation: {
        key: 'key value',
        key_context: 'key_context value',
    }
};

i18next.init({
    supportedLngs: ['en'],
    lng: 'en',
    resources: {
        en: resources,
    },
});

declare module 'i18next' {
    interface CustomTypeOptions {
        resources: typeof resources,
    }
}

const t = i18next.getFixedT('en', 'translation');

const test = t('keyontext');
//              ^ this is a valid key!

Expected behavior

Only key and key_context keys should be inferred.

Your Environment

  • i18next version: 23.15.1
  • typescript: 5.6.2
@marcalexiei

This comment was marked as outdated.

@adrai
Copy link
Member

adrai commented Oct 5, 2024

try v23.15.2

@AlexKrupko
Copy link
Author

Yes, it works like a charm in 23.15.2.
Thank you @adrai, @marcalexiei!

alexandresoro pushed a commit to alexandresoro/ouca that referenced this issue Oct 6, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [i18next](https://www.i18next.com) ([source](https://github.com/i18next/i18next)) | dependencies | minor | [`23.13.0` -> `23.15.2`](https://renovatebot.com/diffs/npm/i18next/23.13.0/23.15.2) |

---

### Release Notes

<details>
<summary>i18next/i18next (i18next)</summary>

### [`v23.15.2`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23152)

[Compare Source](i18next/i18next@v23.15.1...v23.15.2)

-   fix(types): make context related keys detection stricter [2243](i18next/i18next#2243) fixes [2242](i18next/i18next#2242)

### [`v23.15.1`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23151)

[Compare Source](i18next/i18next@v23.15.0...v23.15.1)

-   types(TFunction): make return not inferrable and use defaultValue as return when provided [2234](i18next/i18next#2234)

### [`v23.15.0`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23150)

[Compare Source](i18next/i18next@v23.14.0...v23.15.0)

-   support unescaped variables in TypeScript [2233](i18next/i18next#2233)

### [`v23.14.0`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23140)

[Compare Source](i18next/i18next@v23.13.0...v23.14.0)

-   If backend errors with retry flag, set internal state to 0, so reloadingResources should work [147](i18next/i18next-http-backend#147)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC40MC4wIiwidXBkYXRlZEluVmVyIjoiMzguMTEwLjIiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/43
Reviewed-by: Alexandre Soro <code@soro.dev>
Co-authored-by: renovate <renovate@git.tristess.app>
Co-committed-by: renovate <renovate@git.tristess.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment