Skip to content

Commit

Permalink
Merge pull request #122 from dingjules/master
Browse files Browse the repository at this point in the history
fix return types for i18next.t when returnObjects: true
  • Loading branch information
Romanchuk authored Jun 3, 2024
2 parents c940b05 + 829b8ae commit b409feb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libs/angular-i18next/src/lib/ITranslationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export type ITranslationService = Modify<Partial<i18n.i18n>, {

init(options: i18n.InitOptions): Promise<I18NextLoadResult>;

t(
t<Options extends ITranslationOptions>(
key: string | string[],
options?: ITranslationOptions,
): i18n.TFunctionReturn<i18n.Namespace, string | string[], ITranslationOptions>;
t(
options?: Options,
): i18n.TFunctionReturn<i18n.Namespace, string | string[], Options>;
t<Options extends ITranslationOptions>(
key: string | string[],
defaultValue: string,
options?: ITranslationOptions
): i18n.TFunctionReturn<i18n.Namespace, string | string[], ITranslationOptions>;
options?: Options
): i18n.TFunctionReturn<i18n.Namespace, string | string[], Options>;

format: i18n.FormatFunction;

Expand Down
8 changes: 8 additions & 0 deletions libs/angular-i18next/src/tests/service/I18NextService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe('I18nService', () => {
});
});

it('should be able to return different types while setting returnObjects: true (no typechecking errors)', () => {
const service: ITranslationService = TestBed.inject(I18NEXT_SERVICE);
service.t('some.string') as string;
service.t('some.string', {
returnObjects: true
}) as string[];
});

/*
// does not work because language=cimode ignores default value
// setting language to anything other than 'cimode' breaks the rest of the tests
Expand Down

0 comments on commit b409feb

Please sign in to comment.