use-intl 2.7.3 → 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.3",
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": "96716718eccdc05566b080c55863d7b7e9a0bfdc"
62
+ "gitHead": "6683168cc739943b8a3c7e86585fa614679440e6"
63
63
  }
@@ -17,7 +17,10 @@ import NestedValueOf from './utils/NestedValueOf';
17
17
  * (e.g. `namespace.Component`).
18
18
  */
19
19
  export default function useTranslations<
20
- NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>
20
+ NestedKey extends NamespaceKeys<
21
+ IntlMessages,
22
+ NestedKeyOf<IntlMessages>
23
+ > = never
21
24
  >(
22
25
  namespace?: NestedKey
23
26
  ): // Explicitly defining the return type is necessary as TypeScript would get it wrong
@@ -27,19 +30,12 @@ export default function useTranslations<
27
30
  TargetKey extends MessageKeys<
28
31
  NestedValueOf<
29
32
  {'!': IntlMessages},
30
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
31
- ? '!'
32
- : `!.${NestedKey}`
33
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
33
34
  >,
34
35
  NestedKeyOf<
35
36
  NestedValueOf<
36
37
  {'!': IntlMessages},
37
- NamespaceKeys<
38
- IntlMessages,
39
- NestedKeyOf<IntlMessages>
40
- > extends NestedKey
41
- ? '!'
42
- : `!.${NestedKey}`
38
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
43
39
  >
44
40
  >
45
41
  >
@@ -54,19 +50,12 @@ export default function useTranslations<
54
50
  TargetKey extends MessageKeys<
55
51
  NestedValueOf<
56
52
  {'!': IntlMessages},
57
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
58
- ? '!'
59
- : `!.${NestedKey}`
53
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
60
54
  >,
61
55
  NestedKeyOf<
62
56
  NestedValueOf<
63
57
  {'!': IntlMessages},
64
- NamespaceKeys<
65
- IntlMessages,
66
- NestedKeyOf<IntlMessages>
67
- > extends NestedKey
68
- ? '!'
69
- : `!.${NestedKey}`
58
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
70
59
  >
71
60
  >
72
61
  >
@@ -81,19 +70,12 @@ export default function useTranslations<
81
70
  TargetKey extends MessageKeys<
82
71
  NestedValueOf<
83
72
  {'!': IntlMessages},
84
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
85
- ? '!'
86
- : `!.${NestedKey}`
73
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
87
74
  >,
88
75
  NestedKeyOf<
89
76
  NestedValueOf<
90
77
  {'!': IntlMessages},
91
- NamespaceKeys<
92
- IntlMessages,
93
- NestedKeyOf<IntlMessages>
94
- > extends NestedKey
95
- ? '!'
96
- : `!.${NestedKey}`
78
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
97
79
  >
98
80
  >
99
81
  >
@@ -109,9 +91,7 @@ export default function useTranslations<
109
91
  // The prefix ("!"") is arbitrary, but we have to use some.
110
92
  return useTranslationsImpl<
111
93
  {'!': IntlMessages},
112
- NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey
113
- ? '!'
114
- : `!.${NestedKey}`
94
+ [NestedKey] extends [never] ? '!' : `!.${NestedKey}`
115
95
  >(
116
96
  {'!': messages},
117
97
  // @ts-ignore