i18next 24.1.2 → 24.2.0
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/esm/package.json +1 -1
- package/package.json +1 -1
- package/typescript/options.d.ts +6 -0
- package/typescript/t.d.ts +29 -1
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"24.
|
|
1
|
+
{"type":"module","version":"24.2.0"}
|
package/package.json
CHANGED
package/typescript/options.d.ts
CHANGED
|
@@ -74,6 +74,12 @@ export type TypeOptions = $MergeBy<
|
|
|
74
74
|
*/
|
|
75
75
|
allowObjectInHTMLChildren: false;
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Flag that enables strict key checking even if a `defaultValue` has been provided.
|
|
79
|
+
* This ensures all calls of `t` function don't accidentally use implicitly missing keys.
|
|
80
|
+
*/
|
|
81
|
+
strictKeyChecks: false;
|
|
82
|
+
|
|
77
83
|
/**
|
|
78
84
|
* Prefix for interpolation
|
|
79
85
|
*/
|
package/typescript/t.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ type _InterpolationPrefix = TypeOptions['interpolationPrefix'];
|
|
|
32
32
|
type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
|
|
33
33
|
type _UnescapePrefix = TypeOptions['unescapePrefix'];
|
|
34
34
|
type _UnescapeSuffix = TypeOptions['unescapeSuffix'];
|
|
35
|
+
type _StrictKeyChecks = TypeOptions['strictKeyChecks'];
|
|
35
36
|
|
|
36
37
|
type $IsResourcesDefined = [keyof _Resources] extends [never] ? false : true;
|
|
37
38
|
type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends true
|
|
@@ -278,7 +279,29 @@ type AppendKeyPrefix<Key, KPrefix> = KPrefix extends string
|
|
|
278
279
|
/** ************************
|
|
279
280
|
* T function declaration *
|
|
280
281
|
************************* */
|
|
281
|
-
|
|
282
|
+
|
|
283
|
+
interface TFunctionStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined> {
|
|
284
|
+
$TFunctionBrand: $IsResourcesDefined extends true ? `${$FirstNamespace<Ns>}` : never;
|
|
285
|
+
<
|
|
286
|
+
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
|
|
287
|
+
const TOpt extends TOptions,
|
|
288
|
+
Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, KPrefix>, TOpt>,
|
|
289
|
+
>(
|
|
290
|
+
key: Key | Key[],
|
|
291
|
+
options?: TOpt & InterpolationMap<Ret>,
|
|
292
|
+
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, never>, TOpt>;
|
|
293
|
+
<
|
|
294
|
+
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
|
|
295
|
+
const TOpt extends TOptions,
|
|
296
|
+
Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, KPrefix>, TOpt>,
|
|
297
|
+
>(
|
|
298
|
+
key: Key | Key[],
|
|
299
|
+
defaultValue: string,
|
|
300
|
+
options?: TOpt & InterpolationMap<Ret>,
|
|
301
|
+
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, never>, TOpt>;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface TFunctionNonStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined> {
|
|
282
305
|
$TFunctionBrand: $IsResourcesDefined extends true ? `${$FirstNamespace<Ns>}` : never;
|
|
283
306
|
<
|
|
284
307
|
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
|
|
@@ -294,4 +317,9 @@ export interface TFunction<Ns extends Namespace = DefaultNamespace, KPrefix = un
|
|
|
294
317
|
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, DefaultValue>, TOpt>;
|
|
295
318
|
}
|
|
296
319
|
|
|
320
|
+
export type TFunction<
|
|
321
|
+
Ns extends Namespace = DefaultNamespace,
|
|
322
|
+
KPrefix = undefined,
|
|
323
|
+
> = _StrictKeyChecks extends true ? TFunctionStrict<Ns, KPrefix> : TFunctionNonStrict<Ns, KPrefix>;
|
|
324
|
+
|
|
297
325
|
export type KeyPrefix<Ns extends Namespace> = ResourceKeys<true>[$FirstNamespace<Ns>] | undefined;
|