Update types for lingui__react (#29330)

* Add type for new lingui component

* Add test case
This commit is contained in:
Demian Sempel
2018-10-01 21:04:56 -07:00
committed by Wesley Wigham
parent fdba15d53d
commit 2054910ad2
3 changed files with 22 additions and 4 deletions
+11
View File
@@ -0,0 +1,11 @@
import { Component, ReactNode } from 'react';
import { I18n } from '@lingui/core';
// tslint:disable-next-line:interface-name
export interface I18nComponentProps {
children: ({ i18n, i18nHash }: { i18n: I18n, i18nHash?: string }) => ReactNode;
update?: boolean;
withHash?: boolean;
}
export default class I18nComponent extends Component<I18nComponentProps> {}
+2 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for @lingui/react 2.1
// Type definitions for @lingui/react 2.5
// Project: https://lingui.github.io/js-lingui/
// Definitions by: Jeow Li Huan <https://github.com/huan086>
// Definitions: https://github.com/huan086/lingui-typings
@@ -9,7 +9,7 @@ import { ComponentClass } from 'react';
import { FormatPropsWithoutI18n } from './createFormat';
export { default as withI18n, withI18nProps } from './withI18n';
export { default as I18n } from './I18n';
export { default as I18nProvider } from './I18nProvider';
export { default as Trans } from './Trans';
export { Plural, Select, SelectOrdinal } from './Select';
+9 -2
View File
@@ -3,6 +3,7 @@ import { Catalog, Catalogs, I18n } from '@lingui/core';
import {
withI18n,
I18nProvider,
I18n as I18nComponent,
Trans,
Plural,
Select,
@@ -42,10 +43,16 @@ const App = () => {
const gender = 'male';
const price = 21.35;
const lastLogin = new Date();
const age = 23;
return (
<I18nProvider language="es" catalogs={catalogs}>
<LocalizeAttribute age={23} />
<LocalizeOptionAttribute age={23} />
<LocalizeAttribute age={age} />
<LocalizeOptionAttribute age={age} />
<I18nComponent>
{({ i18n }) => (
<span aria-label={i18n.t('ageId')`${age} years old`}>Attributes</span>
)}
</I18nComponent>
<Trans>Name {name} in <code>Trans</code>.</Trans>
<Trans id="transId">Name {name} in <code>Trans</code> with <code>id</code>.</Trans>
<Plural id="msg.plural"