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

[Types] Return type of "t" is string | MyTranslationsObject #1882

Closed
bhollis opened this issue Dec 13, 2022 · 4 comments
Closed

[Types] Return type of "t" is string | MyTranslationsObject #1882

bhollis opened this issue Dec 13, 2022 · 4 comments

Comments

@bhollis
Copy link

bhollis commented Dec 13, 2022

馃悰 Bug Report

When I import t and use it, with a custom translations type, the return type of t is string | MyTranslationsObject instead of string

To Reproduce

In src/@types/i18next.d.ts:

// import the original type declarations
import 'i18next';

const translations = { Foo: { Bar: 'Hey' } };

declare module 'i18next' {
  interface CustomTypeOptions {
    defaultNS: 'translation';
    resources: { translation: typeof translations };
  }
}

In some other .ts file:

import { t } from 'i18next';

const foo = t('Foo.Bar');

Screenshot 2022-12-12 at 9 11 52 PM

Expected behavior

I expected the type of foo to be string.

Your Environment

  • runtime version: node 18.11
  • i18next version: 22.4.3
  • os: Mac
@adrai
Copy link
Member

adrai commented Dec 13, 2022

seems to work:

i18next.t('bar').trim();

@bhollis
Copy link
Author

bhollis commented Dec 13, 2022

I've changed the original example to use typeof, but it still doesn't work.

Screenshot 2022-12-12 at 10 43 26 PM

Let me check out the i8next repo and try to get a test failing.

bhollis added a commit to bhollis/i18next that referenced this issue Dec 13, 2022
@bhollis
Copy link
Author

bhollis commented Dec 13, 2022

Here you go, this reproduces my issue: bhollis@4b3aca0

@adrai adrai closed this as completed in 0c9f8c9 Dec 13, 2022
@adrai
Copy link
Member

adrai commented Dec 13, 2022

v22.4.4 should fix it

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

2 participants