use-intl 2.7.2 → 2.7.4-alpha.2

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.
@@ -1,42 +1,50 @@
1
- import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from './_virtual/use-intl.esm.js';
2
-
3
- var IntlErrorCode;
4
-
5
- (function (IntlErrorCode) {
6
- IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
7
- IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
8
- IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
9
- IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
10
- IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
11
- IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
12
- })(IntlErrorCode || (IntlErrorCode = {}));
13
-
14
- var IntlError = /*#__PURE__*/function (_Error) {
15
- _inheritsLoose(IntlError, _Error);
16
-
17
- function IntlError(code, originalMessage) {
18
- var _this;
19
-
20
- var message = code;
21
-
22
- if (originalMessage) {
23
- message += ': ' + originalMessage;
24
- }
25
-
26
- _this = _Error.call(this, message) || this;
27
- _this.code = void 0;
28
- _this.originalMessage = void 0;
29
- _this.code = code;
30
-
31
- if (originalMessage) {
32
- _this.originalMessage = originalMessage;
33
- }
34
-
35
- return _this;
36
- }
37
-
38
- return IntlError;
39
- }( /*#__PURE__*/_wrapNativeSuper(Error));
40
-
41
- export { IntlErrorCode, IntlError as default };
1
+ import { useState, useEffect } from 'react';
2
+ import useIntlContext from './use-intl.esm11.js';
3
+
4
+ function getNow() {
5
+ return new Date();
6
+ }
7
+ /**
8
+ * Reading the current date via `new Date()` in components should be avoided, as
9
+ * it causes components to be impure and can lead to flaky tests. Instead, this
10
+ * hook can be used.
11
+ *
12
+ * By default, it returns the time when the component mounts. If `updateInterval`
13
+ * is specified, the value will be updated based on the interval.
14
+ *
15
+ * You can however also return a static value from this hook, if you
16
+ * configure the `now` parameter on the context provider. Note however,
17
+ * that if `updateInterval` is configured in this case, the component
18
+ * will initialize with the global value, but will afterwards update
19
+ * continuously based on the interval.
20
+ *
21
+ * For unit tests, this can be mocked to a constant value. For end-to-end
22
+ * testing, an environment parameter can be passed to the `now` parameter
23
+ * of the provider to mock this to a static value.
24
+ */
25
+
26
+
27
+ function useNow(options) {
28
+ var updateInterval = options == null ? void 0 : options.updateInterval;
29
+
30
+ var _useIntlContext = useIntlContext(),
31
+ globalNow = _useIntlContext.now;
32
+
33
+ var _useState = useState(globalNow || getNow()),
34
+ now = _useState[0],
35
+ setNow = _useState[1];
36
+
37
+ useEffect(function () {
38
+ if (!updateInterval) return;
39
+ var intervalId = setInterval(function () {
40
+ setNow(getNow());
41
+ }, updateInterval);
42
+ return function () {
43
+ clearInterval(intervalId);
44
+ };
45
+ }, [globalNow, updateInterval]);
46
+ return now;
47
+ }
48
+
49
+ export { useNow as default };
42
50
  //# sourceMappingURL=use-intl.esm8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../src/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","code","originalMessage","message","Error"],"mappings":";;IAAYA,cAAZ;;AAAA,CAAA,UAAYA,aAAZ,EAAyB;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAA,CAAA;AACD,CAPD,EAAYA,aAAa,KAAbA,aAAa,GAOxB,EAPwB,CAAzB,CAAA,CAAA;;IASqBC;;;AAInB,EAAYC,SAAAA,SAAAA,CAAAA,IAAZ,EAAiCC,eAAjC,EAAyD;AAAA,IAAA,IAAA,KAAA,CAAA;;AACvD,IAAIC,IAAAA,OAAO,GAAWF,IAAtB,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnBC,MAAAA,OAAO,IAAI,IAAA,GAAOD,eAAlB,CAAA;AACD,KAAA;;AACD,IAAA,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAMC,OAAN,CAAA,IAAA,IAAA,CAAA;AALuD,IAAA,KAAA,CAHzCF,IAGyC,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,KAAA,CAFzCC,eAEyC,GAAA,KAAA,CAAA,CAAA;AAOvD,IAAKD,KAAAA,CAAAA,IAAL,GAAYA,IAAZ,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnB,MAAKA,KAAAA,CAAAA,eAAL,GAAuBA,eAAvB,CAAA;AACD,KAAA;;AAVsD,IAAA,OAAA,KAAA,CAAA;AAWxD,GAAA;;;iCAfoCE;;;;"}
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../src/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
@@ -1,6 +1,32 @@
1
- import { createContext } from 'react';
1
+ import IntlError, { IntlErrorCode } from './use-intl.esm5.js';
2
2
 
3
- var IntlContext = /*#__PURE__*/createContext(undefined);
3
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
+ Object.entries(messages).forEach(function (_ref) {
5
+ var key = _ref[0],
6
+ messageOrMessages = _ref[1];
4
7
 
5
- export { IntlContext as default };
8
+ if (key.includes('.')) {
9
+ var keyLabel = key;
10
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
11
+ invalidKeyLabels.push(keyLabel);
12
+ }
13
+
14
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
15
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
16
+ return part != null;
17
+ }).join('.'));
18
+ }
19
+ });
20
+ }
21
+
22
+ function validateMessages(messages, onError) {
23
+ var invalidKeyLabels = [];
24
+ validateMessagesSegment(messages, invalidKeyLabels);
25
+
26
+ if (invalidKeyLabels.length > 0) {
27
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
28
+ }
29
+ }
30
+
31
+ export { validateMessages as default };
6
32
  //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../src/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../src/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,CAAJ,EAAuB;AACrB,MAAIC,IAAAA,QAAQ,GAAGH,GAAf,CAAA;AACA,MAAA,IAAIJ,UAAJ,EAAgBO,QAAQ,IAAA,OAAA,GAAYP,UAAZ,GAAR,GAAA,CAAA;AAChBD,MAAAA,gBAAgB,CAACS,IAAjB,CAAsBD,QAAtB,CAAA,CAAA;AACD,KAAA;;AAED,IAAIF,IAAAA,iBAAiB,IAAI,IAArB,IAA6B,OAAOA,iBAAP,KAA6B,QAA9D,EAAwE;AACtER,MAAAA,uBAAuB,CACrBQ,iBADqB,EAErBN,gBAFqB,EAGrB,CAACC,UAAD,EAAaI,GAAb,CAAA,CAAkBK,MAAlB,CAAyB,UAACC,IAAD,EAAA;AAAA,QAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,OAAzB,CAAiDC,CAAAA,IAAjD,CAAsD,GAAtD,CAHqB,CAAvB,CAAA;AAKD,KAAA;AACF,GAdD,CAAA,CAAA;AAeD,CAAA;;AAEa,SAAUC,gBAAV,CACZd,QADY,EAEZe,OAFY,EAEuB;AAEnC,EAAMd,IAAAA,gBAAgB,GAAkB,EAAxC,CAAA;AACAF,EAAAA,uBAAuB,CAACC,QAAD,EAAWC,gBAAX,CAAvB,CAAA;;AAEA,EAAA,IAAIA,gBAAgB,CAACe,MAAjB,GAA0B,CAA9B,EAAiC;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAJ,CACEC,aAAa,CAACC,WADhB,EAAA,2JAAA,IAGIlB,gBAAgB,CAACe,MAAjB,KAA4B,CAA5B,GAAgC,KAAhC,GAAwC,MAH5C,CAIOf,GAAAA,IAAAA,GAAAA,gBAAgB,CAACY,IAAjB,CAAsB,IAAtB,CAJP,CADK,CAAP,CAAA;AAQD,GAAA;AACF;;;;"}
@@ -13,20 +13,32 @@ import NestedValueOf from './utils/NestedValueOf';
13
13
  * The namespace can also indicate nesting by using a dot
14
14
  * (e.g. `namespace.Component`).
15
15
  */
16
- export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>>(namespace?: NestedKey): {
16
+ export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
17
17
  <TargetKey extends MessageKeys<NestedValueOf<{
18
18
  '!': IntlMessages;
19
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
19
+ }, [
20
+ NestedKey
21
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
20
22
  '!': IntlMessages;
21
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
23
+ }, [
24
+ NestedKey
25
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
22
26
  rich<TargetKey extends MessageKeys<NestedValueOf<{
23
27
  '!': IntlMessages;
24
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
28
+ }, [
29
+ NestedKey
30
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
25
31
  '!': IntlMessages;
26
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
32
+ }, [
33
+ NestedKey
34
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
27
35
  raw<TargetKey extends MessageKeys<NestedValueOf<{
28
36
  '!': IntlMessages;
29
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
37
+ }, [
38
+ NestedKey
39
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
30
40
  '!': IntlMessages;
31
- }, NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
41
+ }, [
42
+ NestedKey
43
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
32
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "2.7.2",
3
+ "version": "2.7.4-alpha.2",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.me>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -59,5 +59,5 @@
59
59
  "engines": {
60
60
  "node": ">=10"
61
61
  },
62
- "gitHead": "0e4dd6047240d66186b376eaf9c9b6d18dee3c53"
62
+ "gitHead": "6683168cc739943b8a3c7e86585fa614679440e6"
63
63
  }
@@ -1,6 +1,5 @@
1
1
  import {ReactElement, ReactNodeArray} from 'react';
2
2
  import Formats from './Formats';
3
- import IntlError, {IntlErrorCode} from './IntlError';
4
3
  import TranslationValues, {RichTranslationValues} from './TranslationValues';
5
4
  import useIntlContext from './useIntlContext';
6
5
  import useTranslationsImpl from './useTranslationsImpl';
@@ -18,7 +17,10 @@ import NestedValueOf from './utils/NestedValueOf';
18
17
  * (e.g. `namespace.Component`).
19
18
  */
20
19
  export default function useTranslations<
21
- NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>
20
+ NestedKey extends NamespaceKeys<
21
+ IntlMessages,
22
+ NestedKeyOf<IntlMessages>
23
+ > = never
22
24
  >(
23
25
  namespace?: NestedKey
24
26
  ): // Explicitly defining the return type is necessary as TypeScript would get it wrong
@@ -28,19 +30,12 @@ export default function useTranslations<
28
30
  TargetKey extends MessageKeys<
29
31
  NestedValueOf<
30
32
  {'!': IntlMessages},
31
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
32
- ? '!'
33
- : `!.${NestedKey}`
33
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
34
34
  >,
35
35
  NestedKeyOf<
36
36
  NestedValueOf<
37
37
  {'!': IntlMessages},
38
- NamespaceKeys<
39
- IntlMessages,
40
- NestedKeyOf<IntlMessages>
41
- > extends NestedKey
42
- ? '!'
43
- : `!.${NestedKey}`
38
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
44
39
  >
45
40
  >
46
41
  >
@@ -55,19 +50,12 @@ export default function useTranslations<
55
50
  TargetKey extends MessageKeys<
56
51
  NestedValueOf<
57
52
  {'!': IntlMessages},
58
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
59
- ? '!'
60
- : `!.${NestedKey}`
53
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
61
54
  >,
62
55
  NestedKeyOf<
63
56
  NestedValueOf<
64
57
  {'!': IntlMessages},
65
- NamespaceKeys<
66
- IntlMessages,
67
- NestedKeyOf<IntlMessages>
68
- > extends NestedKey
69
- ? '!'
70
- : `!.${NestedKey}`
58
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
71
59
  >
72
60
  >
73
61
  >
@@ -82,19 +70,12 @@ export default function useTranslations<
82
70
  TargetKey extends MessageKeys<
83
71
  NestedValueOf<
84
72
  {'!': IntlMessages},
85
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
86
- ? '!'
87
- : `!.${NestedKey}`
73
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
88
74
  >,
89
75
  NestedKeyOf<
90
76
  NestedValueOf<
91
77
  {'!': IntlMessages},
92
- NamespaceKeys<
93
- IntlMessages,
94
- NestedKeyOf<IntlMessages>
95
- > extends NestedKey
96
- ? '!'
97
- : `!.${NestedKey}`
78
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
98
79
  >
99
80
  >
100
81
  >
@@ -103,25 +84,14 @@ export default function useTranslations<
103
84
  ): any;
104
85
  } {
105
86
  const context = useIntlContext();
106
-
107
87
  const messages = context.messages as IntlMessages;
108
- if (!messages) {
109
- const intlError = new IntlError(
110
- IntlErrorCode.MISSING_MESSAGE,
111
- __DEV__ ? `No messages were configured on the provider.` : undefined
112
- );
113
- context.onError(intlError);
114
- throw intlError;
115
- }
116
88
 
117
89
  // We have to wrap the actual hook so the type inference for the optional
118
90
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
119
91
  // The prefix ("!"") is arbitrary, but we have to use some.
120
92
  return useTranslationsImpl<
121
93
  {'!': IntlMessages},
122
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
123
- ? '!'
124
- : `!.${NestedKey}`
94
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
125
95
  >(
126
96
  {'!': messages},
127
97
  // @ts-ignore