Simplify types

This commit is contained in:
Karol Janyst
2017-03-23 09:09:54 +09:00
parent 3add527a22
commit 722699bb4b
3 changed files with 13 additions and 26 deletions
+10 -11
View File
@@ -6,6 +6,10 @@
declare namespace ReactIntl {
interface Values {
[key: string]: string;
}
interface Locale {
locale: string;
fields?: { [key: string]: string },
@@ -61,20 +65,18 @@ declare namespace ReactIntl {
formatRelative: (value: number, 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?: any) => string;
formatHTMLMessage: (messageDescriptor: FormattedMessage.MessageDescriptor, values?: any) => string;
}
interface InjectedConfig {
formatMessage: (messageDescriptor: FormattedMessage.MessageDescriptor, values?: Values) => string;
formatHTMLMessage: (messageDescriptor: FormattedMessage.MessageDescriptor, values?: Values) => string;
locale: string;
formats: any;
messages: { [id: string]: string };
defaultLocale: string;
defaultFormats: any;
now : () => number;
}
interface InjectedIntlProps {
intl: InjectedIntl & InjectedConfig & { now : () => number };
intl: InjectedIntl;
}
namespace IntlComponent {
@@ -103,7 +105,7 @@ declare namespace ReactIntl {
class FormattedTime extends React.Component<FormattedTime.Props, any> { }
namespace FormattedRelative {
interface Base {
export interface PropsBase {
/*
* one of "second", "minute", "hour", "day", "month" or "year"
*/
@@ -113,9 +115,6 @@ declare namespace ReactIntl {
*/
style?: "best-fit" | "numeric";
format?: string;
}
export interface PropsBase extends Base {
updateInterval?: number;
initialNow?: any;
}
@@ -135,7 +134,7 @@ declare namespace ReactIntl {
}
export interface Props extends MessageDescriptor {
values?: any;
values?: Values;
tagName?: string;
}
}
+2 -13
View File
@@ -58,22 +58,11 @@ const SomeFunctionalComponentWithIntl: React.ComponentClass<SomeComponentProps>
);
});
@injectIntl
class SomeDecoratedComponentWithIntl extends React.Component<SomeComponentProps & InjectedIntlProps, any> {
public render () {
const {
intl : { formatMessage }
} = this.props;
return (<div />);
}
}
class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlProps, void> {
static propTypes: React.ValidationMap<any> = {
intl: intlShape.isRequired
};
public render(): React.ReactElement<{}> {
render(): React.ReactElement<{}> {
const intl = this.props.intl;
const formattedDate = intl.formatDate(new Date(), { format: "short" });
const formattedTime = intl.formatTime(new Date(), { format: "short" });
@@ -182,7 +171,7 @@ class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlPro
const SomeComponentWithIntl: React.ComponentClass<SomeComponentProps> = injectIntl(SomeComponent);
class TestApp extends React.Component<{}, {}> {
public render(): React.ReactElement<{}> {
render(): React.ReactElement<{}> {
const definedMessages = defineMessages({
"sup": {
id: "sup",
+1 -2
View File
@@ -19,7 +19,6 @@
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true
"forceConsistentCasingInFileNames": true
}
}