Merge pull request #16720 from gfx/react-intl/FormattedDate

fix type of react-intl/{FormattedDate,FormattedTime,FormattedRelative} types
This commit is contained in:
Yui
2017-06-01 08:35:51 -07:00
committed by GitHub
2 changed files with 42 additions and 6 deletions
+8 -6
View File
@@ -11,6 +11,8 @@
declare namespace ReactIntl {
type DateSource = Date | string | number;
interface Locale {
locale: string;
fields?: { [key: string]: string },
@@ -62,9 +64,9 @@ declare namespace ReactIntl {
const intlShape: IntlShape;
interface InjectedIntl {
formatDate: (date: Date, options?: FormattedDate.PropsBase) => string;
formatTime: (date: Date, options?: FormattedTime.PropsBase) => string;
formatRelative: (value: number, options?: FormattedRelative.PropsBase & { now?: any }) => string;
formatDate: (value: DateSource, options?: FormattedDate.PropsBase) => string;
formatTime: (value: DateSource, options?: FormattedTime.PropsBase) => string;
formatRelative: (value: DateSource, options?: FormattedRelative.PropsBase & { now?: any }) => string;
formatNumber: (value: number, options?: FormattedNumber.PropsBase) => string;
formatPlural: (value: number, options?: FormattedPlural.Base) => keyof FormattedPlural.PropsBase;
formatMessage: (messageDescriptor: FormattedMessage.MessageDescriptor, values?: {[key: string]: string | number}) => string;
@@ -91,7 +93,7 @@ declare namespace ReactIntl {
export interface PropsBase extends IntlComponent.DateTimeFormatProps {}
export interface Props extends PropsBase {
value: Date;
value: DateSource;
}
}
@@ -101,7 +103,7 @@ declare namespace ReactIntl {
export interface PropsBase extends IntlComponent.DateTimeFormatProps {}
export interface Props extends PropsBase {
value: Date;
value: DateSource;
}
}
class FormattedTime extends React.Component<FormattedTime.Props, any> { }
@@ -122,7 +124,7 @@ declare namespace ReactIntl {
}
export interface Props extends PropsBase {
value: number;
value: DateSource;
}
}
+34
View File
@@ -165,6 +165,23 @@ class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlPro
second="2-digit"
timeZoneName="short" />
<FormattedDate
value={Date.now()}
format="short"
localeMatcher="best fit"
formatMatcher="basic"
timeZone="EDT"
hour12={false}
weekday="short"
era="short"
year="2-digit"
month="2-digit"
day="2-digit"
hour="2-digit"
minute="2-digit"
second="2-digit"
timeZoneName="short" />
<FormattedTime
value={new Date()}
format="short"
@@ -182,6 +199,23 @@ class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlPro
second="2-digit"
timeZoneName="short" />
<FormattedTime
value={Date.now()}
format="short"
localeMatcher="best fit"
formatMatcher="basic"
timeZone="EDT"
hour12={false}
weekday="short"
era="short"
year="2-digit"
month="2-digit"
day="2-digit"
hour="2-digit"
minute="2-digit"
second="2-digit"
timeZoneName="short" />
<FormattedNumber value={123}>
{(formattedNum: string) => (
<span className="number">{formattedNum}</span>