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)
Reproduction: angular-i18next issue demo
While passing
returnObjects: true
toITranslationService .t()
I'm getting type match errorType 'string' is not assignable to type 'string[]'.
With
returnObjects: true
, the return type is supposed to be objects or arrays, butITranslationService .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