Support for strictNullChecks

This commit is contained in:
abeall
2017-12-12 13:16:23 -05:00
parent 89b156be87
commit 267157dfba
3 changed files with 17 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
declare namespace ReactIntl {
type DateSource = Date | string | number;
type MessageValue = string | number | boolean | Date | null | undefined;
interface Locale {
locale: string;
@@ -69,8 +70,8 @@ declare namespace ReactIntl {
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 | boolean | Date}): string;
formatHTMLMessage(messageDescriptor: FormattedMessage.MessageDescriptor, values?: {[key: string]: string | number | boolean | Date}): string;
formatMessage(messageDescriptor: FormattedMessage.MessageDescriptor, values?: {[key: string]: MessageValue}): string;
formatHTMLMessage(messageDescriptor: FormattedMessage.MessageDescriptor, values?: {[key: string]: MessageValue}): string;
locale: string;
formats: any;
messages: { [id: string]: string };
@@ -138,7 +139,7 @@ declare namespace ReactIntl {
}
interface Props extends MessageDescriptor {
values?: {[key: string]: string | number | boolean | Date | JSX.Element};
values?: {[key: string]: MessageValue | JSX.Element};
tagName?: string;
}
}

View File

@@ -50,12 +50,12 @@ const SomeFunctionalComponentWithIntl: React.ComponentClass<SomeComponentProps>
const formattedRelative = formatRelative(new Date().getTime(), { format: "short" });
const formattedNumber = formatNumber(123, { format: "short" });
const formattedPlural = formatPlural(1, { style: "ordinal" });
const formattedMessage = formatMessage({ id: "hello", defaultMessage: "Hello {name}!" }, { name: "Roger" });
const formattedMessage = formatMessage({ id: "hello", defaultMessage: "Hello {name}!" }, { name: "Roger", nullAllowed: null, undefinedAllowed: undefined });
const formattedMessagePlurals = formatMessage({
id: "hello",
defaultMessage: "Hello {name} you have {unreadCount, number} {unreadCount, plural, one {message} other {messages}}!" },
{ name: "Roger", unreadCount: 123 });
const formattedHTMLMessage = formatHTMLMessage({ id: "hello", defaultMessage: "Hello <strong>{name}</strong>!" }, { name: "Roger" });
defaultMessage: "Hello {name} you have {unreadCount, number} {unreadCount, plural, one {message} other {messages}}!"
}, { name: "Roger", unreadCount: 123 });
const formattedHTMLMessage = formatHTMLMessage({ id: "hello", defaultMessage: "Hello <strong>{name}</strong>!" }, { name: "Roger", nullAllowed: null, undefinedAllowed: undefined });
return (
<div className={className}>
</div>
@@ -136,6 +136,13 @@ class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlPro
values={{ valueOne: 1, valueTen: 10 }}
tagName="div" />
<FormattedMessage
id="test"
description="Test"
defaultMessage="Hi {blank} and {empty}!"
values={{ blank: null, empty: undefined }}
tagName="div" />
<FormattedHTMLMessage
id="test"
description="Test"

View File

@@ -11,7 +11,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
@@ -22,4 +22,4 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
}