From 1f1491ee8b65ab25365e0e1f7a4b52ba3c71da0b Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Wed, 24 May 2017 22:47:26 +0900 Subject: [PATCH] fix type of react-intl/{FormattedDate,FormattedTime,FormattedRelative} --- types/react-intl/index.d.ts | 14 ++++++----- types/react-intl/react-intl-tests.tsx | 34 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/types/react-intl/index.d.ts b/types/react-intl/index.d.ts index 2b55a471ec..9777987c8d 100644 --- a/types/react-intl/index.d.ts +++ b/types/react-intl/index.d.ts @@ -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 { } @@ -122,7 +124,7 @@ declare namespace ReactIntl { } export interface Props extends PropsBase { - value: number; + value: DateSource; } } diff --git a/types/react-intl/react-intl-tests.tsx b/types/react-intl/react-intl-tests.tsx index a9717147e9..8b21ef8651 100644 --- a/types/react-intl/react-intl-tests.tsx +++ b/types/react-intl/react-intl-tests.tsx @@ -165,6 +165,23 @@ class SomeComponent extends React.Component + + + + {(formattedNum: string) => ( {formattedNum}