react-intl 4.2.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOp
29
29
  export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
30
30
  export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
31
31
  export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
32
- export interface IntlFormatters<T = React.ReactNode> {
32
+ export interface IntlFormatters<T = React.ReactNode, R = T> {
33
33
  formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
34
34
  formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
35
35
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -39,7 +39,7 @@ export interface IntlFormatters<T = React.ReactNode> {
39
39
  formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
40
40
  formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
41
41
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
42
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
42
+ formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
43
43
  formatList(values: Array<string>, opts?: FormatListOptions): string;
44
44
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
45
45
  formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
@@ -6,7 +6,7 @@ export interface Props<V extends Record<string, any> = Record<string, React.Reac
6
6
  tagName?: React.ElementType<any>;
7
7
  children?(...nodes: React.ReactNodeArray): React.ReactNode;
8
8
  }
9
- declare class FormattedMessage<T = React.ReactNode, V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>> extends React.Component<Props<V>> {
9
+ declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props<V>> {
10
10
  static displayName: string;
11
11
  static defaultProps: {
12
12
  values: {};
package/lib/error.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { MessageDescriptor } from "./types";
1
2
  export declare const enum ReactIntlErrorCode {
2
3
  FORMAT_ERROR = "FORMAT_ERROR",
3
4
  UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
@@ -6,6 +7,7 @@ export declare const enum ReactIntlErrorCode {
6
7
  MISSING_TRANSLATION = "MISSING_TRANSLATION"
7
8
  }
8
9
  export declare class ReactIntlError extends Error {
9
- code: ReactIntlErrorCode;
10
- constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
10
+ readonly code: ReactIntlErrorCode;
11
+ readonly descriptor?: MessageDescriptor;
12
+ constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
11
13
  }
package/lib/error.js CHANGED
@@ -1,7 +1,16 @@
1
+ export var ReactIntlErrorCode;
2
+ (function (ReactIntlErrorCode) {
3
+ ReactIntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
4
+ ReactIntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
5
+ ReactIntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
6
+ ReactIntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
7
+ ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
8
+ })(ReactIntlErrorCode || (ReactIntlErrorCode = {}));
1
9
  export class ReactIntlError extends Error {
2
- constructor(code, message, exception) {
10
+ constructor(code, message, descriptor, exception) {
3
11
  super(`[React Intl Error ${code}] ${message} ${exception ? `\n${exception.stack}` : ''}`);
4
12
  this.code = code;
13
+ this.descriptor = descriptor;
5
14
  if (typeof Error.captureStackTrace === 'function') {
6
15
  Error.captureStackTrace(this, ReactIntlError);
7
16
  }
@@ -12,7 +12,7 @@ export function formatDisplayName({ locale, onError }, getDisplayNames, value, o
12
12
  if (!DisplayNames) {
13
13
  onError(new FormatError(`Intl.DisplayNames is not available in this environment.
14
14
  Try polyfilling it using "@formatjs/intl-displaynames"
15
- `, 2 /* MISSING_INTL_API */));
15
+ `, "MISSING_INTL_API" /* MISSING_INTL_API */));
16
16
  }
17
17
  const filteredOptions = filterProps(options, DISPLAY_NAMES_OPTONS);
18
18
  try {
@@ -15,7 +15,7 @@ export function formatList({ locale, onError }, getListFormat, values, options =
15
15
  if (!ListFormat) {
16
16
  onError(new FormatError(`Intl.ListFormat is not available in this environment.
17
17
  Try polyfilling it using "@formatjs/intl-listformat"
18
- `, 2 /* MISSING_INTL_API */));
18
+ `, "MISSING_INTL_API" /* MISSING_INTL_API */));
19
19
  }
20
20
  const filteredOptions = filterProps(options, LIST_FORMAT_OPTIONS);
21
21
  try {
@@ -47,7 +47,7 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
47
47
  }
48
48
  catch (e) {
49
49
  onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting message: "${id}" for locale: "${locale}"` +
50
- (defaultMessage ? ', using default message as fallback.' : ''), e));
50
+ (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor, e));
51
51
  }
52
52
  }
53
53
  else if (!defaultMessage ||
@@ -56,7 +56,7 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
56
56
  // when no `messages` are passed into the <IntlProvider> for the
57
57
  // default locale.
58
58
  onError(new ReactIntlError("MISSING_TRANSLATION" /* MISSING_TRANSLATION */, `Missing message: "${id}" for locale: "${locale}"` +
59
- (defaultMessage ? ', using default message as fallback.' : '')));
59
+ (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor));
60
60
  }
61
61
  if (!formattedMessageParts && defaultMessage) {
62
62
  try {
@@ -64,12 +64,12 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
64
64
  formattedMessageParts = formatter.format(values);
65
65
  }
66
66
  catch (e) {
67
- onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting the default message for: "${id}"`, e));
67
+ onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting the default message for: "${id}"`, messageDescriptor, e));
68
68
  }
69
69
  }
70
70
  if (!formattedMessageParts) {
71
71
  onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Cannot format message: "${id}", ` +
72
- `using message ${message || defaultMessage ? 'source' : 'id'} as fallback.`));
72
+ `using message ${message || defaultMessage ? 'source' : 'id'} as fallback.`, messageDescriptor));
73
73
  if (typeof message === 'string') {
74
74
  return message || defaultMessage || String(id);
75
75
  }
@@ -9,7 +9,7 @@ export function formatPlural({ locale, onError }, getPluralRules, value, options
9
9
  if (!Intl.PluralRules) {
10
10
  onError(new FormatError(`Intl.PluralRules is not available in this environment.
11
11
  Try polyfilling it using "@formatjs/intl-pluralrules"
12
- `, 2 /* MISSING_INTL_API */));
12
+ `, "MISSING_INTL_API" /* MISSING_INTL_API */));
13
13
  }
14
14
  const filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
15
15
  try {
@@ -19,7 +19,7 @@ export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, o
19
19
  if (!RelativeTimeFormat) {
20
20
  config.onError(new FormatError(`Intl.RelativeTimeFormat is not available in this environment.
21
21
  Try polyfilling it using "@formatjs/intl-relativetimeformat"
22
- `, 2 /* MISSING_INTL_API */));
22
+ `, "MISSING_INTL_API" /* MISSING_INTL_API */));
23
23
  }
24
24
  try {
25
25
  return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
package/lib/index.js CHANGED
@@ -18,4 +18,4 @@ export { default as FormattedRelativeTime } from './components/relative';
18
18
  export { default as FormattedPlural } from './components/plural';
19
19
  export { default as FormattedMessage } from './components/message';
20
20
  export { createIntlCache } from './utils';
21
- export { ReactIntlError } from './error';
21
+ export { ReactIntlError, ReactIntlErrorCode } from './error';
@@ -65,7 +65,7 @@ export declare const FormattedList: React.FC<IntlListFormatOptions & {
65
65
  value: React.ReactNode[];
66
66
  }>;
67
67
 
68
- export declare class FormattedMessage<T = React.ReactNode, V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>> extends React.Component<Props_3<V>> {
68
+ export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props_3<V>> {
69
69
  static displayName: string;
70
70
  static defaultProps: {
71
71
  values: {};
@@ -162,7 +162,7 @@ export declare interface IntlConfig {
162
162
 
163
163
  export declare const IntlContext: React.Context<IntlShape>;
164
164
 
165
- export declare interface IntlFormatters<T = React.ReactNode> {
165
+ export declare interface IntlFormatters<T = React.ReactNode, R = T> {
166
166
  formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
167
167
  formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
168
168
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -172,7 +172,7 @@ export declare interface IntlFormatters<T = React.ReactNode> {
172
172
  formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
173
173
  formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
174
174
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
175
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
175
+ formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
176
176
  formatList(values: Array<string>, opts?: FormatListOptions): string;
177
177
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
178
178
  formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
@@ -235,8 +235,9 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
235
235
  export declare const RawIntlProvider: React.Provider<IntlShape>;
236
236
 
237
237
  export declare class ReactIntlError extends Error {
238
- code: ReactIntlErrorCode;
239
- constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
238
+ readonly code: ReactIntlErrorCode;
239
+ readonly descriptor?: MessageDescriptor;
240
+ constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
240
241
  }
241
242
 
242
243
  export declare const enum ReactIntlErrorCode {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.7.10"
8
+ "packageVersion": "7.7.11"
9
9
  }
10
10
  ]
11
11
  }
package/lib/types.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOp
29
29
  export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
30
30
  export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
31
31
  export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
32
- export interface IntlFormatters<T = React.ReactNode> {
32
+ export interface IntlFormatters<T = React.ReactNode, R = T> {
33
33
  formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
34
34
  formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
35
35
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -39,7 +39,7 @@ export interface IntlFormatters<T = React.ReactNode> {
39
39
  formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
40
40
  formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
41
41
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
42
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
42
+ formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
43
43
  formatList(values: Array<string>, opts?: FormatListOptions): string;
44
44
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
45
45
  formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intl",
3
- "version": "4.2.0",
3
+ "version": "4.3.1",
4
4
  "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -140,7 +140,7 @@
140
140
  "@types/invariant": "^2.2.31",
141
141
  "hoist-non-react-statics": "^3.3.2",
142
142
  "intl-format-cache": "^4.2.22",
143
- "intl-messageformat": "^8.2.2",
143
+ "intl-messageformat": "^8.3.2",
144
144
  "intl-messageformat-parser": "^4.1.1",
145
145
  "shallow-equal": "^1.2.1"
146
146
  },
@@ -153,19 +153,19 @@
153
153
  "@babel/plugin-proposal-class-properties": "^7.8.3",
154
154
  "@babel/plugin-transform-modules-commonjs": "^7.9.0",
155
155
  "@babel/preset-env": "^7.9.0",
156
- "@babel/preset-react": "^7.9.1",
156
+ "@babel/preset-react": "^7.9.4",
157
157
  "@formatjs/intl-pluralrules": "^1.5.3",
158
- "@microsoft/api-documenter": "^7.7.14",
159
- "@microsoft/api-extractor": "^7.7.10",
158
+ "@microsoft/api-documenter": "^7.7.15",
159
+ "@microsoft/api-extractor": "^7.7.11",
160
160
  "@types/benchmark": "^1.0.31",
161
161
  "@types/enzyme": "^3.10.5",
162
162
  "@types/jest": "^25.1.4",
163
163
  "@types/prop-types": "^15.7.3",
164
- "@types/react": "^16.9.25",
164
+ "@types/react": "^16.9.26",
165
165
  "@types/react-dom": "^16.9.5",
166
- "@typescript-eslint/eslint-plugin": "^2.24.0",
167
- "@typescript-eslint/parser": "^2.24.0",
168
- "babel-jest": "^25.1.0",
166
+ "@typescript-eslint/eslint-plugin": "^2.25.0",
167
+ "@typescript-eslint/parser": "^2.25.0",
168
+ "babel-jest": "^25.2.3",
169
169
  "benchmark": "^2.1.4",
170
170
  "core-js": "^3.6.4",
171
171
  "cross-env": "^7.0.2",
@@ -177,7 +177,7 @@
177
177
  "fs-extra": "^9.0.0",
178
178
  "full-icu": "^1.3.1",
179
179
  "glob": "^7.1.6",
180
- "jest": "^25.1.0",
180
+ "jest": "^25.2.3",
181
181
  "markdown-toc": "^1.2.0",
182
182
  "mkdirp": "^1.0.3",
183
183
  "parcel": "^1.12.4",
@@ -186,7 +186,7 @@
186
186
  "react": "^16.13.1",
187
187
  "react-dom": "^16.13.1",
188
188
  "rimraf": "^3.0.2",
189
- "rollup": "^2.1.0",
189
+ "rollup": "^2.2.0",
190
190
  "rollup-plugin-babel": "^4.4.0",
191
191
  "rollup-plugin-commonjs": "^10.1.0",
192
192
  "rollup-plugin-node-resolve": "^5.2.0",
@@ -195,9 +195,9 @@
195
195
  "rollup-plugin-uglify": "^6.0.4",
196
196
  "standard-version": "^7.1.0",
197
197
  "ts-jest": "^25.2.1",
198
- "ts-node": "^8.7.0",
198
+ "ts-node": "^8.8.1",
199
199
  "tslib": "^1.11.1",
200
- "typescript": "^3.8.3"
200
+ "typescript": "3.8"
201
201
  },
202
202
  "scripts": {
203
203
  "benchmark": "cross-env NODE_ENV=production TS_NODE_PROJECT=./tsconfig.cjs.json ts-node test/perf/index.tsx",
@@ -22,7 +22,7 @@ function defaultFormatMessage<T = React.ReactNode>(
22
22
  descriptor: MessageDescriptor,
23
23
  values?: Record<
24
24
  string,
25
- PrimitiveType | React.ReactElement | FormatXMLElementFn<T>
25
+ PrimitiveType | React.ReactElement | FormatXMLElementFn<T, T>
26
26
  >
27
27
  ): string {
28
28
  if (process.env.NODE_ENV !== 'production') {
@@ -51,10 +51,11 @@ export interface Props<
51
51
  }
52
52
 
53
53
  class FormattedMessage<
54
- T = React.ReactNode,
55
54
  V extends Record<string, any> = Record<
56
55
  string,
57
- PrimitiveType | React.ReactElement | FormatXMLElementFn<T>
56
+ | PrimitiveType
57
+ | React.ReactElement
58
+ | FormatXMLElementFn<React.ReactNode, React.ReactNode>
58
59
  >
59
60
  > extends React.Component<Props<V>> {
60
61
  static displayName = 'FormattedMessage';
package/src/error.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { MessageDescriptor } from "./types"
2
+
1
3
  export const enum ReactIntlErrorCode {
2
4
  FORMAT_ERROR = 'FORMAT_ERROR',
3
5
  UNSUPPORTED_FORMATTER = 'UNSUPPORTED_FORMATTER',
@@ -7,10 +9,12 @@ export const enum ReactIntlErrorCode {
7
9
  }
8
10
 
9
11
  export class ReactIntlError extends Error {
10
- public code: ReactIntlErrorCode
11
- constructor(code: ReactIntlErrorCode, message: string, exception?: Error) {
12
+ public readonly code: ReactIntlErrorCode
13
+ public readonly descriptor?: MessageDescriptor
14
+ constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error) {
12
15
  super(`[React Intl Error ${code}] ${message} ${exception ? `\n${exception.stack}` : ''}`)
13
16
  this.code = code
17
+ this.descriptor = descriptor
14
18
  if (typeof Error.captureStackTrace === 'function') {
15
19
  Error.captureStackTrace(this, ReactIntlError)
16
20
  }
@@ -72,8 +72,8 @@ function deepMergeFormatsAndSetTimeZone(
72
72
  };
73
73
  }
74
74
 
75
- function prepareIntlMessageFormatHtmlOutput<T>(
76
- chunks: (string | T)[]
75
+ function prepareIntlMessageFormatHtmlOutput(
76
+ chunks: React.ReactNodeArray
77
77
  ): React.ReactElement {
78
78
  return React.createElement(React.Fragment, null, ...chunks);
79
79
  }
@@ -99,7 +99,7 @@ export function formatMessage(
99
99
  messageDescriptor?: MessageDescriptor,
100
100
  values?: Record<string, PrimitiveType>
101
101
  ): string;
102
- export function formatMessage<T>(
102
+ export function formatMessage(
103
103
  {
104
104
  locale,
105
105
  formats,
@@ -125,14 +125,9 @@ export function formatMessage<T>(
125
125
  values:
126
126
  | Record<
127
127
  string,
128
- | string
129
- | number
130
- | boolean
128
+ | React.ReactNode
131
129
  | Date
132
- | T
133
- | FormatXMLElementFn<T>
134
- | null
135
- | undefined
130
+ | FormatXMLElementFn<React.ReactNode, React.ReactNode>
136
131
  >
137
132
  | undefined = {}
138
133
  ): React.ReactNode {
@@ -144,7 +139,7 @@ export function formatMessage<T>(
144
139
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
145
140
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
146
141
 
147
- let formattedMessageParts: string | T | (string | T)[] = '';
142
+ let formattedMessageParts: React.ReactNode = '';
148
143
 
149
144
  if (message) {
150
145
  try {
@@ -152,13 +147,14 @@ export function formatMessage<T>(
152
147
  formatters: state,
153
148
  });
154
149
 
155
- formattedMessageParts = formatter.format(values);
150
+ formattedMessageParts = formatter.format<React.ReactNode>(values);
156
151
  } catch (e) {
157
152
  onError(
158
153
  new ReactIntlError(
159
154
  ReactIntlErrorCode.FORMAT_ERROR,
160
155
  `Error formatting message: "${id}" for locale: "${locale}"` +
161
156
  (defaultMessage ? ', using default message as fallback.' : ''),
157
+ messageDescriptor,
162
158
  e
163
159
  )
164
160
  );
@@ -174,7 +170,8 @@ export function formatMessage<T>(
174
170
  new ReactIntlError(
175
171
  ReactIntlErrorCode.MISSING_TRANSLATION,
176
172
  `Missing message: "${id}" for locale: "${locale}"` +
177
- (defaultMessage ? ', using default message as fallback.' : '')
173
+ (defaultMessage ? ', using default message as fallback.' : ''),
174
+ messageDescriptor
178
175
  )
179
176
  );
180
177
  }
@@ -193,6 +190,7 @@ export function formatMessage<T>(
193
190
  new ReactIntlError(
194
191
  ReactIntlErrorCode.FORMAT_ERROR,
195
192
  `Error formatting the default message for: "${id}"`,
193
+ messageDescriptor,
196
194
  e
197
195
  )
198
196
  );
@@ -206,7 +204,8 @@ export function formatMessage<T>(
206
204
  `Cannot format message: "${id}", ` +
207
205
  `using message ${
208
206
  message || defaultMessage ? 'source' : 'id'
209
- } as fallback.`
207
+ } as fallback.`,
208
+ messageDescriptor
210
209
  )
211
210
  );
212
211
  if (typeof message === 'string') {
@@ -216,11 +215,9 @@ export function formatMessage<T>(
216
215
  }
217
216
  if (Array.isArray(formattedMessageParts)) {
218
217
  if (wrapRichTextChunksInFragment) {
219
- return prepareIntlMessageFormatHtmlOutput<T>(
220
- formattedMessageParts as Array<string | T>
221
- );
218
+ return prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
222
219
  }
223
220
  return formattedMessageParts;
224
221
  }
225
- return formattedMessageParts as string | T;
222
+ return formattedMessageParts as React.ReactNode;
226
223
  }
package/src/types.ts CHANGED
@@ -67,7 +67,7 @@ export type FormatDisplayNameOptions = Exclude<
67
67
  'localeMatcher'
68
68
  >;
69
69
 
70
- export interface IntlFormatters<T = React.ReactNode> {
70
+ export interface IntlFormatters<T = React.ReactNode, R = T> {
71
71
  formatDate(
72
72
  value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
73
73
  opts?: FormatDateOptions
@@ -109,7 +109,7 @@ export interface IntlFormatters<T = React.ReactNode> {
109
109
  descriptor: MessageDescriptor,
110
110
  values?: Record<
111
111
  string,
112
- PrimitiveType | React.ReactElement | FormatXMLElementFn<T>
112
+ PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>
113
113
  >
114
114
  ): string | React.ReactNodeArray;
115
115
  formatList(values: Array<string>, opts?: FormatListOptions): string;