Skip to content

Commit

Permalink
Add defaultValue tests and allow second arg string to be interpreted …
Browse files Browse the repository at this point in the history
…as defaultValue (#1206)
  • Loading branch information
rosskevin committed Feb 13, 2019
1 parent 4e4c75b commit 69f7402
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -485,7 +485,7 @@ declare namespace i18next {
TInterpolationMap extends object = StringMap
>(
key: TKeys | TKeys[],
options?: TOptions<TInterpolationMap>,
options?: TOptions<TInterpolationMap> | string,
) => TResult;

interface Resource {
Expand Down
19 changes: 15 additions & 4 deletions test/typescript/t.test.ts
Expand Up @@ -8,10 +8,6 @@ function basicUsage(t: i18next.TFunction) {
t(['friend', 'tree'], { myVar: 'someValue' });
}

/**
* Use of the exported TFunction in external utility methods such as
* NamespaceConsumer children t
*/
function returnCasts(t: i18next.TFunction) {
const s: string = t('friend'); // same as <string>
const s2: string = t`friend`;
Expand All @@ -20,6 +16,21 @@ function returnCasts(t: i18next.TFunction) {
const oa: object[] = t<object[]>('friend');
}

function defautValue(t: i18next.TFunction) {
t('translation:test', { defaultValue: 'test_en' });
t('translation:test', { defaultValue: 'test_en', count: 1 });
t('translation:test', {
defaultValue_plural: 'test_en_plural',
defaultValue: 'test_en',
count: 10,
});

// string (only) default value as second arg
// https://www.i18next.com/translation-function/essentials#passing-a-default-value
// https://github.com/i18next/i18next/blob/master/src/Translator.js#L66
t('translation:test', 'test_en');
}

function callsMethodWithOptionalArg(t: i18next.TFunction) {
function displayHint(hint?: string) {
return String(hint);
Expand Down

0 comments on commit 69f7402

Please sign in to comment.