Skip to content

Commit

Permalink
Add t function to TransProps types (#969)
Browse files Browse the repository at this point in the history
* Add t function to TransProps types

* Add usage test
  • Loading branch information
valgussev authored and rosskevin committed Oct 23, 2019
1 parent 2d67848 commit 8d84b7d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface TransProps extends Partial<i18next.WithT> {
parent?: React.ReactNode;
tOptions?: {};
values?: {};
t?: i18next.TFunction;
}
export function Trans(props: TransProps): any;

Expand Down
56 changes: 56 additions & 0 deletions test/typescript/Trans.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from 'react';
import { Trans, useTranslation } from 'react-i18next';

function basic() {
return <Trans>Foo</Trans>;
}

function children() {
return (
<Trans>
<div />
</Trans>
);
}

function components() {
return <Trans components={[<div />]}>Foo</Trans>;
}

function count() {
return <Trans count={42}>Foo</Trans>;
}

function defaults() {
return <Trans defaults={'defaults'}>Foo</Trans>;
}

function i18n() {
const { i18n } = useTranslation();
return <Trans i18n={i18n}>Foo</Trans>;
}

function i18nKey() {
return <Trans i18nKey={'i18nKey'}>Foo</Trans>;
}

function ns() {
return <Trans ns={'ns'}>Foo</Trans>;
}

function parent() {
return <Trans parent={<div />}>Foo</Trans>;
}

function tOptions() {
return <Trans tOptions={{}}>Foo</Trans>;
}

function values() {
return <Trans values={{}}>Foo</Trans>;
}

function t() {
const { t } = useTranslation();
return <Trans t={t}>Foo</Trans>;
}

0 comments on commit 8d84b7d

Please sign in to comment.