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

Typing issue when returnObjects: true #121

Closed
dingjules opened this issue May 6, 2024 · 2 comments · Fixed by #122
Closed

Typing issue when returnObjects: true #121

dingjules opened this issue May 6, 2024 · 2 comments · Fixed by #122

Comments

@dingjules
Copy link

Reproduction: angular-i18next issue demo

While passing returnObjects: true to ITranslationService .t() I'm getting type match error Type 'string' is not assignable to type 'string[]'.

With returnObjects: true, the return type is supposed to be objects or arrays, but ITranslationService .t() will always return string.

I also checked directly with i18next.t() which works correctly by returning a $SpecialObject, the type is ready to be casted into custom types as described in doc

import * as i18n from 'i18next';
import { ITranslationService } from 'angular-i18next';

// i18next Correct returning types

// good
const _returnTypeIsString: string = i18n.t('some.string');

// good
const _returnTypeCanBeCasted: string[] = i18n.t('some.string', {
  returnObjects: true,
});

// angular-i18next always return string even with returnObjects: true,
const service1: ITranslationService = {
  t: () => '',
} as unknown as ITranslationService;

// good
const _returnTypeShouldBeString: string = service1.t('some.string');

// bad
const _returnTypeShouldBeCasted: string[] = service1.t('some.string', {
  returnObjects: true,
}); // Type 'string' is not assignable to type 'string[]'.(2322)
@Romanchuk
Copy link
Owner

Thanks, will check it out on this week

@Romanchuk
Copy link
Owner

Version: v17.0.2 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants