|
1 |
| -import type AbstractIntlMessages from './AbstractIntlMessages.js'; |
2 |
| -import type {Locale} from './AppConfig.js'; |
| 1 | +import type {Locale, Messages} from './AppConfig.js'; |
3 | 2 | import type Formats from './Formats.js';
|
4 | 3 | import type IntlError from './IntlError.js';
|
5 | 4 | import type TimeZone from './TimeZone.js';
|
| 5 | +import type {DeepPartial} from './types.js'; |
6 | 6 |
|
7 | 7 | /**
|
8 | 8 | * Should be used for entry points that configure the library.
|
9 | 9 | */
|
10 | 10 |
|
11 |
| -type IntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> = |
12 |
| - { |
13 |
| - /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */ |
14 |
| - locale: Locale; |
15 |
| - /** Global formats can be provided to achieve consistent |
16 |
| - * formatting across components. */ |
17 |
| - formats?: Formats; |
18 |
| - /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */ |
19 |
| - timeZone?: TimeZone; |
20 |
| - /** This callback will be invoked when an error is encountered during |
21 |
| - * resolving a message or formatting it. This defaults to `console.error` to |
22 |
| - * keep your app running. You can customize the handling by taking |
23 |
| - * `error.code` into account. */ |
24 |
| - onError?(error: IntlError): void; |
25 |
| - /** Will be called when a message couldn't be resolved or formatting it led to |
26 |
| - * an error. This defaults to `${namespace}.${key}` You can use this to |
27 |
| - * customize what will be rendered in this case. */ |
28 |
| - getMessageFallback?(info: { |
29 |
| - error: IntlError; |
30 |
| - key: string; |
31 |
| - namespace?: string; |
32 |
| - }): string; |
33 |
| - /** |
34 |
| - * Providing this value will have two effects: |
35 |
| - * 1. It will be used as the default for the `now` argument of |
36 |
| - * `useFormatter().formatRelativeTime` if no explicit value is provided. |
37 |
| - * 2. It will be returned as a static value from the `useNow` hook. Note |
38 |
| - * however that when `updateInterval` is configured on the `useNow` hook, |
39 |
| - * the global `now` value will only be used for the initial render, but |
40 |
| - * afterwards the current date will be returned continuously. |
41 |
| - */ |
42 |
| - now?: Date; |
43 |
| - /** All messages that will be available. */ |
44 |
| - messages?: Messages; |
45 |
| - }; |
| 11 | +type IntlConfig = { |
| 12 | + /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */ |
| 13 | + locale: Locale; |
| 14 | + /** Global formats can be provided to achieve consistent |
| 15 | + * formatting across components. */ |
| 16 | + formats?: Formats; |
| 17 | + /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */ |
| 18 | + timeZone?: TimeZone; |
| 19 | + /** This callback will be invoked when an error is encountered during |
| 20 | + * resolving a message or formatting it. This defaults to `console.error` to |
| 21 | + * keep your app running. You can customize the handling by taking |
| 22 | + * `error.code` into account. */ |
| 23 | + onError?(error: IntlError): void; |
| 24 | + /** Will be called when a message couldn't be resolved or formatting it led to |
| 25 | + * an error. This defaults to `${namespace}.${key}` You can use this to |
| 26 | + * customize what will be rendered in this case. */ |
| 27 | + getMessageFallback?(info: { |
| 28 | + error: IntlError; |
| 29 | + key: string; |
| 30 | + namespace?: string; |
| 31 | + }): string; |
| 32 | + /** |
| 33 | + * Providing this value will have two effects: |
| 34 | + * 1. It will be used as the default for the `now` argument of |
| 35 | + * `useFormatter().formatRelativeTime` if no explicit value is provided. |
| 36 | + * 2. It will be returned as a static value from the `useNow` hook. Note |
| 37 | + * however that when `updateInterval` is configured on the `useNow` hook, |
| 38 | + * the global `now` value will only be used for the initial render, but |
| 39 | + * afterwards the current date will be returned continuously. |
| 40 | + */ |
| 41 | + now?: Date; |
| 42 | + /** All messages that will be available. */ |
| 43 | + messages?: DeepPartial<Messages>; |
| 44 | +}; |
46 | 45 |
|
| 46 | +/** |
47 | 47 | /**
|
48 | 48 | * A stricter set of the configuration that should be used internally
|
49 | 49 | * once defaults are assigned to `IntlConfiguration`.
|
50 | 50 | */
|
51 |
| -export type InitializedIntlConfig< |
52 |
| - Messages extends AbstractIntlMessages = AbstractIntlMessages |
53 |
| -> = IntlConfig<Messages> & { |
54 |
| - onError: NonNullable<IntlConfig<Messages>['onError']>; |
55 |
| - getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>; |
| 51 | +export type InitializedIntlConfig = IntlConfig & { |
| 52 | + onError: NonNullable<IntlConfig['onError']>; |
| 53 | + getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>; |
56 | 54 | };
|
57 | 55 |
|
58 | 56 | export default IntlConfig;
|
0 commit comments