i18next 26.7.2 → 27.0.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/typescript/t.d.ts CHANGED
@@ -16,20 +16,29 @@ import type {
16
16
  TOptionsBase,
17
17
  } from './options.js';
18
18
 
19
+ // Only the declarations marked `export` are public: without an export list, every declaration of a
20
+ // .d.ts module counts as exported, and the `_` and `$` helpers below were importable.
21
+ export {};
22
+
19
23
  /** @todo consider to replace {} with Record<string, never> */
20
24
 
21
25
  // Type Options
22
26
  type _ReturnObjects = TypeOptions['returnObjects'];
23
27
  type _ReturnEmptyString = TypeOptions['returnEmptyString'];
24
28
  type _ReturnNull = TypeOptions['returnNull'];
25
- type _KeySeparator = TypeOptions['keySeparator'];
29
+ // `keySeparator: false`: flat keys only (a `false` here made `nestedfalsec` keys and split keys at the
30
+ // text "false")
31
+ type _KeySeparator = Exclude<TypeOptions['keySeparator'], false>;
32
+ // what getFixedT() joins a key prefix and a key with: '.' when keySeparator is false
33
+ type _KeyPrefixSeparator = TypeOptions['keySeparator'] extends false
34
+ ? '.'
35
+ : TypeOptions['keySeparator'];
26
36
  // `nsSeparator: false`: no `ns:key` keys (a `false` here made `nsfalsekey` keys and split keys containing "false")
27
37
  type _NsSeparator = Exclude<TypeOptions['nsSeparator'], false>;
28
38
  type _PluralSeparator = TypeOptions['pluralSeparator'];
29
39
  type _ContextSeparator = TypeOptions['contextSeparator'];
30
40
  type _FallbackNamespace = TypeOptions['fallbackNS'];
31
41
  type _Resources = TypeOptions['resources'];
32
- type _CompatibilityJSON = TypeOptions['compatibilityJSON'];
33
42
  type _InterpolationPrefix = TypeOptions['interpolationPrefix'];
34
43
  type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
35
44
  type _InterpolationFormatSeparator = TypeOptions['interpolationFormatSeparator'];
@@ -48,22 +57,24 @@ type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends tru
48
57
  : Fallback;
49
58
  type $FirstNamespace<Ns extends Namespace> = Ns extends readonly any[] ? Ns[0] : Ns;
50
59
 
51
- type Resources = $ValueIfResourcesDefined<_Resources, $Dictionary<string>>;
60
+ export type Resources = $ValueIfResourcesDefined<_Resources, $Dictionary<string>>;
52
61
 
53
- type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
62
+ export type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
54
63
 
55
- type WithOrWithoutPlural<Key> = _CompatibilityJSON extends 'v4'
56
- ? Key extends `${infer KeyWithoutOrdinalPlural}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`
64
+ export type WithOrWithoutPlural<Key> =
65
+ Key extends `${infer KeyWithoutOrdinalPlural}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`
57
66
  ? KeyWithoutOrdinalPlural | Key
58
67
  : Key extends `${infer KeyWithoutPlural}${_PluralSeparator}${PluralSuffix}`
59
68
  ? KeyWithoutPlural | Key
60
- : Key
61
- : Key;
69
+ : Key;
62
70
 
63
- type JoinKeys<K1, K2> = `${K1 & string}${_KeySeparator}${K2 & string}`;
64
- type AppendNamespace<Ns, Keys> = `${Ns & string}${_NsSeparator}${Keys & string}`;
71
+ export type JoinKeys<K1, K2> = `${K1 & string}${_KeySeparator}${K2 & string}`;
72
+ export type AppendNamespace<Ns, Keys> = `${Ns & string}${_NsSeparator}${Keys & string}`;
65
73
 
66
- type TrimSpaces<T extends string, Acc extends string = ''> = T extends `${infer Char}${infer Rest}`
74
+ export type TrimSpaces<
75
+ T extends string,
76
+ Acc extends string = '',
77
+ > = T extends `${infer Char}${infer Rest}`
67
78
  ? Char extends ' '
68
79
  ? TrimSpaces<Rest, Acc>
69
80
  : TrimSpaces<Rest, `${Acc}${Char}`>
@@ -71,7 +82,7 @@ type TrimSpaces<T extends string, Acc extends string = ''> = T extends `${infer
71
82
  ? Acc
72
83
  : never;
73
84
 
74
- interface Branded<Ns extends Namespace> {
85
+ export interface Branded<Ns extends Namespace> {
75
86
  $TFunctionBrand: $IsResourcesDefined extends true
76
87
  ? `${Ns extends readonly any[] ? Ns[0] : Ns}`
77
88
  : never;
@@ -104,7 +115,7 @@ type _ValueOf<Res, Key> =
104
115
  // conditional types, so `KeyPrefix<Ns>` no longer resolves to a literal union
105
116
  // and `keyPrefix` inference widens to the whole namespace, polluting `t()`
106
117
  // return types with sibling keys (#2434 regression). Guard `never` in the merge.
107
- type KeysBuilderWithReturnObjects<Res, Key = keyof Res> =
118
+ export type KeysBuilderWithReturnObjects<Res, Key = keyof Res> =
108
119
  Key extends _KeysOf<Res>
109
120
  ? Res[Key] extends $Dictionary | readonly unknown[]
110
121
  ? | JoinKeys<Key, WithOrWithoutPlural<keyof $OmitArrayKeys<Res[Key]>>>
@@ -112,27 +123,27 @@ type KeysBuilderWithReturnObjects<Res, Key = keyof Res> =
112
123
  : never
113
124
  : never;
114
125
 
115
- type KeysBuilderWithoutReturnObjects<Res, Key = keyof $OmitArrayKeys<Res>> =
126
+ export type KeysBuilderWithoutReturnObjects<Res, Key = keyof $OmitArrayKeys<Res>> =
116
127
  Key extends _KeysOf<Res>
117
128
  ? Res[Key] extends $Dictionary | readonly unknown[]
118
129
  ? JoinKeys<Key, KeysBuilderWithoutReturnObjects<Res[Key]>>
119
130
  : Key
120
131
  : never;
121
132
 
122
- type KeysBuilder<Res, WithReturnObjects> = $IsResourcesDefined extends true
133
+ export type KeysBuilder<Res, WithReturnObjects> = $IsResourcesDefined extends true
123
134
  ? WithReturnObjects extends true
124
135
  ? keyof Res | KeysBuilderWithReturnObjects<Res>
125
136
  : KeysBuilderWithoutReturnObjects<Res>
126
137
  : string;
127
138
 
128
- type KeysWithReturnObjects = {
139
+ export type KeysWithReturnObjects = {
129
140
  [Ns in FlatNamespace]: WithOrWithoutPlural<KeysBuilder<Resources[Ns], true>>;
130
141
  };
131
- type KeysWithoutReturnObjects = {
142
+ export type KeysWithoutReturnObjects = {
132
143
  [Ns in FlatNamespace]: WithOrWithoutPlural<KeysBuilder<Resources[Ns], false>>;
133
144
  };
134
145
 
135
- type ResourceKeys<WithReturnObjects = _ReturnObjects> = WithReturnObjects extends true
146
+ export type ResourceKeys<WithReturnObjects = _ReturnObjects> = WithReturnObjects extends true
136
147
  ? KeysWithReturnObjects
137
148
  : KeysWithoutReturnObjects;
138
149
 
@@ -147,19 +158,22 @@ export type NsByTOptions<Ns extends Namespace, TOpt extends TOptions> = TOpt['ns
147
158
  ? TOpt['ns']
148
159
  : Ns;
149
160
 
150
- type ParseKeysByKeyPrefix<Keys, KPrefix> = KPrefix extends string
151
- ? Keys extends `${KPrefix}${_KeySeparator}${infer Key}`
161
+ export type ParseKeysByKeyPrefix<Keys, KPrefix> = KPrefix extends string
162
+ ? Keys extends `${KPrefix}${_KeyPrefixSeparator}${infer Key}`
152
163
  ? Key
153
164
  : never
154
165
  : Keys;
155
166
 
156
- type ParseKeysByNamespaces<Ns extends Namespace, Keys> = Ns extends readonly (infer UnionNsps)[]
167
+ export type ParseKeysByNamespaces<
168
+ Ns extends Namespace,
169
+ Keys,
170
+ > = Ns extends readonly (infer UnionNsps)[]
157
171
  ? UnionNsps extends keyof Keys
158
172
  ? AppendNamespace<UnionNsps, Keys[UnionNsps]>
159
173
  : never
160
174
  : never;
161
175
 
162
- type ParseKeysByFallbackNs<Keys extends $Dictionary> = _FallbackNamespace extends false
176
+ export type ParseKeysByFallbackNs<Keys extends $Dictionary> = _FallbackNamespace extends false
163
177
  ? never
164
178
  : _FallbackNamespace extends (infer UnionFallbackNs extends string)[]
165
179
  ? Keys[UnionFallbackNs]
@@ -192,12 +206,13 @@ export type ParseKeys<
192
206
  /** *******************************************************
193
207
  * Parse t function return type and interpolation values *
194
208
  ******************************************************** */
195
- type ParseActualValue<Ret> = Ret extends `${_UnescapePrefix}${infer ActualValue}${_UnescapeSuffix}`
196
- ? TrimSpaces<ActualValue>
197
- : Ret;
209
+ export type ParseActualValue<Ret> =
210
+ Ret extends `${_UnescapePrefix}${infer ActualValue}${_UnescapeSuffix}`
211
+ ? TrimSpaces<ActualValue>
212
+ : Ret;
198
213
 
199
214
  /** Parses interpolation entries as `[variableName, formatSpecifier | never]` tuples. */
200
- type ParseInterpolationEntries<Ret> = [_ParseInterpolation] extends [false | 'icu' | 'mf2']
215
+ export type ParseInterpolationEntries<Ret> = [_ParseInterpolation] extends [false | 'icu' | 'mf2']
201
216
  ? never
202
217
  : Ret extends `${string}${_InterpolationPrefix}${infer Value}${_InterpolationSuffix}${infer Rest}`
203
218
  ? | (Value extends `${infer ActualValue}${_InterpolationFormatSeparator}${infer Format}`
@@ -207,7 +222,7 @@ type ParseInterpolationEntries<Ret> = [_ParseInterpolation] extends [false | 'ic
207
222
  : never;
208
223
 
209
224
  /** Extracts just the variable names (kept for backward compat with ParseInterpolationValues usage). */
210
- type ParseInterpolationValues<Ret> = ParseInterpolationEntries<Ret>[0];
225
+ export type ParseInterpolationValues<Ret> = ParseInterpolationEntries<Ret>[0];
211
226
 
212
227
  /** Built-in i18next formatter name → value type mapping. */
213
228
  type _BuiltInFormatTypeMap = {
@@ -452,20 +467,20 @@ export type InterpolationMap<Ret> = _WithDefaultVariables<
452
467
  >
453
468
  >;
454
469
 
455
- type ParseTReturnPlural<
470
+ export type ParseTReturnPlural<
456
471
  Res,
457
472
  Key,
458
473
  KeyWithPlural = `${Key & string}${_PluralSeparator}${PluralSuffix}`,
459
474
  > = _ValueOf<Res, KeyWithPlural | Key>;
460
475
 
461
- type ParseTReturnPluralOrdinal<
476
+ export type ParseTReturnPluralOrdinal<
462
477
  Res,
463
478
  Key,
464
479
  KeyWithOrdinalPlural = `${Key &
465
480
  string}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`,
466
481
  > = _ValueOf<Res, KeyWithOrdinalPlural | Key>;
467
482
 
468
- type ParseTReturnWithFallback<Key, Val> = Val extends ''
483
+ export type ParseTReturnWithFallback<Key, Val> = Val extends ''
469
484
  ? _ReturnEmptyString extends true
470
485
  ? ''
471
486
  : Key
@@ -475,7 +490,7 @@ type ParseTReturnWithFallback<Key, Val> = Val extends ''
475
490
  : Key
476
491
  : Val;
477
492
 
478
- type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
493
+ export type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
479
494
  Key,
480
495
  Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
481
496
  ? ParseTReturn<RestKey, _ValueOf<Res, K1>, TOpt>
@@ -492,13 +507,14 @@ type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallba
492
507
  : _ValueOf<Res, Key>
493
508
  >;
494
509
 
495
- type TReturnOptionalNull = _ReturnNull extends true ? null : never;
496
- type TReturnOptionalObjects<TOpt extends { returnObjects?: unknown }> = _ReturnObjects extends true
497
- ? $SpecialObject | string
498
- : TOpt['returnObjects'] extends true
499
- ? $SpecialObject
500
- : string;
501
- type DefaultTReturn<TOpt extends { returnObjects?: unknown }> =
510
+ export type TReturnOptionalNull = _ReturnNull extends true ? null : never;
511
+ export type TReturnOptionalObjects<TOpt extends { returnObjects?: unknown }> =
512
+ _ReturnObjects extends true
513
+ ? $SpecialObject | string
514
+ : TOpt['returnObjects'] extends true
515
+ ? $SpecialObject
516
+ : string;
517
+ export type DefaultTReturn<TOpt extends { returnObjects?: unknown }> =
502
518
  TReturnOptionalObjects<TOpt> | TReturnOptionalNull;
503
519
 
504
520
  export type KeyWithContext<Key, TOpt extends TOptions> = TOpt['context'] extends string
@@ -527,7 +543,7 @@ export type ContextOfKey<
527
543
  : string;
528
544
 
529
545
  // helper that maps the configured fallbackNS value to the matching resources slice
530
- type FallbackResourcesOf<FallbackNS, R> = FallbackNS extends readonly (infer FN)[]
546
+ export type FallbackResourcesOf<FallbackNS, R> = FallbackNS extends readonly (infer FN)[]
531
547
  ? R[FN & keyof R]
532
548
  : [FallbackNS] extends [false]
533
549
  ? never
@@ -552,14 +568,18 @@ export type TFunctionReturn<
552
568
  TOpt extends TOptions,
553
569
  ActualNS extends Namespace = NsByTOptions<Ns, TOpt>,
554
570
  ActualKey = KeyWithContext<Key, TOpt>,
571
+ // a key without a value, e.g. a plural key without `count`
572
+ NotFound = DefaultTReturn<TOpt>,
555
573
  > = $IsResourcesDefined extends true
556
574
  ? ActualKey extends `${infer Nsp}${_NsSeparator}${infer RestKey}`
557
- ? ParseTReturn<RestKey, Resources[Nsp & keyof Resources], TOpt>
575
+ ? [ParseTReturn<RestKey, Resources[Nsp & keyof Resources], TOpt>] extends [never]
576
+ ? NotFound
577
+ : ParseTReturn<RestKey, Resources[Nsp & keyof Resources], TOpt>
558
578
  : $FirstNamespace<ActualNS> extends infer PrimaryNS
559
579
  ? [PrimaryNS] extends [keyof Resources]
560
580
  ? [_PrimaryParse<ActualKey, PrimaryNS & keyof Resources, TOpt>] extends [never]
561
581
  ? [_FallbackParse<ActualKey, _FallbackNamespace, TOpt>] extends [never]
562
- ? DefaultTReturn<TOpt>
582
+ ? NotFound
563
583
  : _FallbackParse<ActualKey, _FallbackNamespace, TOpt>
564
584
  : _PrimaryParse<ActualKey, PrimaryNS & keyof Resources, TOpt>
565
585
  : never
@@ -593,25 +613,27 @@ export type TFunctionDetailedResult<T = string, TOpt extends TOptions = {}> = {
593
613
  usedParams: InterpolationMap<T> & { count?: TOpt['count'] };
594
614
  };
595
615
 
596
- type TFunctionProcessReturnValue<Ret, DefaultValue> = Ret extends string | $SpecialObject | null
616
+ export type TFunctionProcessReturnValue<Ret, DefaultValue> = Ret extends
617
+ string | $SpecialObject | null
597
618
  ? Ret
598
619
  : [DefaultValue] extends [never]
599
620
  ? Ret
600
621
  : DefaultValue;
601
622
 
602
- type TFunctionReturnOptionalDetails<Ret, TOpt extends TOptions> = TOpt['returnDetails'] extends true
603
- ? TFunctionDetailedResult<Ret, TOpt>
604
- : Ret;
623
+ export type TFunctionReturnOptionalDetails<
624
+ Ret,
625
+ TOpt extends TOptions,
626
+ > = TOpt['returnDetails'] extends true ? TFunctionDetailedResult<Ret, TOpt> : Ret;
605
627
 
606
- type AppendKeyPrefix<Key, KPrefix> = KPrefix extends string
607
- ? `${KPrefix}${_KeySeparator}${Key & string}`
628
+ export type AppendKeyPrefix<Key, KPrefix> = KPrefix extends string
629
+ ? `${KPrefix}${_KeyPrefixSeparator}${Key & string}`
608
630
  : Key;
609
631
 
610
632
  /**
611
633
  * Resolves the effective key prefix by preferring a per-call `keyPrefix` from
612
634
  * options over the interface-level `KPrefix` (set via getFixedT's 3rd argument).
613
635
  */
614
- type EffectiveKPrefix<KPrefix, TOpt> = TOpt extends { keyPrefix: infer OptKP extends string }
636
+ export type EffectiveKPrefix<KPrefix, TOpt> = TOpt extends { keyPrefix: infer OptKP extends string }
615
637
  ? OptKP
616
638
  : KPrefix;
617
639
 
@@ -652,6 +674,61 @@ type _IfOptionalOptions<Ret> = _RequiresMessageOptions extends true
652
674
  ? unknown
653
675
  : { 'pass these arguments as t() options': InterpolationMap<Ret> }
654
676
  : unknown;
677
+ /**
678
+ * What a call without options is checked against: `Ret`, unless a key without a
679
+ * value of its own (a plural key without `count`) widened it to `string`, which
680
+ * hid the variables of every other key in a union. Only with
681
+ * `strictInterpolationChecks`: without it (ICU and MF2 check their arguments
682
+ * regardless of the flag) the types are the v26 ones.
683
+ */
684
+ type _CheckedReturn<
685
+ Ret,
686
+ Ns extends Namespace,
687
+ Key,
688
+ TOpt extends TOptions,
689
+ > = _StrictInterpolationChecks extends true
690
+ ? string extends Ret
691
+ ? _CheckedValue<Ns, Key, TOpt>
692
+ : Ret
693
+ : Ret;
694
+ /**
695
+ * Per key: its value, or the plural forms of a key without one; `never` (not
696
+ * `string`) for a key without either. The first lookup is the one `Ret` made
697
+ * (cached), so only a key without a value is looked up again.
698
+ */
699
+ type _CheckedValue<Ns extends Namespace, Key, TOpt extends TOptions> = Key extends unknown
700
+ ? TFunctionReturn<
701
+ Ns,
702
+ Key,
703
+ TOpt,
704
+ NsByTOptions<Ns, TOpt>,
705
+ KeyWithContext<Key, TOpt>,
706
+ never
707
+ > extends infer V
708
+ ? [V] extends [never]
709
+ ? _ValueWithCount<NsByTOptions<Ns, TOpt>, KeyWithContext<Key, TOpt>>
710
+ : V
711
+ : never
712
+ : never;
713
+ /** The plural forms of a key, ordinal ones too, `never` for a key without them. */
714
+ type _ValueWithCount<
715
+ Ns extends Namespace,
716
+ Key,
717
+ K = Key | `${Key & string}${_PluralSeparator}ordinal`,
718
+ > = TFunctionReturn<Ns, K, { count: number }, Ns, K, never>;
719
+ /**
720
+ * The variables a call with options must pass. With `strictInterpolationChecks`
721
+ * those of `_CheckedReturn`, so a plural key without `count` needs the variables
722
+ * of its forms, `count` included; without the flag those of `Ret`, as in v26.
723
+ */
724
+ type _OptionsMap<
725
+ Ret,
726
+ Ns extends Namespace,
727
+ Key,
728
+ TOpt extends TOptions,
729
+ > = _StrictInterpolationChecks extends true
730
+ ? InterpolationMap<$NoInfer<_CheckedReturn<Ret, Ns, Key, TOpt>>>
731
+ : InterpolationMap<Ret>;
655
732
  /** Options parameter of a selector overload: required for a message with arguments. */
656
733
  type _SelectorOptionsArg<Ret, Opts> =
657
734
  unknown extends _IfOptionalOptions<Ret> ? [options?: Opts] : [options: Opts];
@@ -679,7 +756,7 @@ type _SelectorArrayOptionsArg<R, Opts> =
679
756
  * T function declaration *
680
757
  ************************* */
681
758
 
682
- interface TFunctionStrict<
759
+ export interface TFunctionStrict<
683
760
  Ns extends Namespace = DefaultNamespace,
684
761
  KPrefix = undefined,
685
762
  > extends Branded<Ns> {
@@ -690,7 +767,7 @@ interface TFunctionStrict<
690
767
  >(
691
768
  key: Key | Key[],
692
769
  options: TOpt &
693
- InterpolationMap<Ret> & {
770
+ _OptionsMap<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt> & {
694
771
  context?: Key extends string
695
772
  ? unknown extends TOpt['context']
696
773
  ? TOpt['context']
@@ -703,7 +780,12 @@ interface TFunctionStrict<
703
780
  const TOpt extends TOptions,
704
781
  Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>,
705
782
  >(
706
- key: (Key | Key[]) & _IfOptionalOptions<$NoInfer<Ret>>,
783
+ key: (Key | Key[]) &
784
+ _IfOptionalOptions<
785
+ $NoInfer<
786
+ _CheckedReturn<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>
787
+ >
788
+ >,
707
789
  ): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, never>, TOpt>;
708
790
  <
709
791
  const Key extends ParseKeys<Ns, TOpt, EffectiveKPrefix<KPrefix, TOpt>> | TemplateStringsArray,
@@ -713,7 +795,7 @@ interface TFunctionStrict<
713
795
  key: Key | Key[],
714
796
  defaultValue: string,
715
797
  options: TOpt &
716
- InterpolationMap<Ret> & {
798
+ _OptionsMap<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt> & {
717
799
  context?: Key extends string
718
800
  ? unknown extends TOpt['context']
719
801
  ? TOpt['context']
@@ -726,12 +808,17 @@ interface TFunctionStrict<
726
808
  const TOpt extends TOptions,
727
809
  Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>,
728
810
  >(
729
- key: (Key | Key[]) & _IfOptionalDefaultOptions<$NoInfer<Ret>>,
811
+ key: (Key | Key[]) &
812
+ _IfOptionalDefaultOptions<
813
+ $NoInfer<
814
+ _CheckedReturn<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>
815
+ >
816
+ >,
730
817
  defaultValue: string,
731
818
  ): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, never>, TOpt>;
732
819
  }
733
820
 
734
- interface TFunctionNonStrict<
821
+ export interface TFunctionNonStrict<
735
822
  Ns extends Namespace = DefaultNamespace,
736
823
  KPrefix = undefined,
737
824
  > extends Branded<Ns> {
@@ -740,14 +827,14 @@ interface TFunctionNonStrict<
740
827
  const TOpt extends TOptions,
741
828
  Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>,
742
829
  const ActualOptions extends Omit<TOpt, 'context'> &
743
- InterpolationMap<Ret> & {
830
+ _OptionsMap<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt> & {
744
831
  context?: Key extends string
745
832
  ? unknown extends TOpt['context']
746
833
  ? TOpt['context']
747
834
  : ContextOfKey<Key, Ns, TOpt, EffectiveKPrefix<KPrefix, TOpt>>
748
835
  : never;
749
836
  } = TOpt &
750
- InterpolationMap<Ret> & {
837
+ _OptionsMap<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt> & {
751
838
  context?: Key extends string
752
839
  ? unknown extends TOpt['context']
753
840
  ? TOpt['context']
@@ -765,11 +852,17 @@ interface TFunctionNonStrict<
765
852
  | [key: string | string[], options: TOpt & $Dictionary & { defaultValue: DefaultValue }]
766
853
  | [key: string | string[], defaultValue: DefaultValue]
767
854
  | [key: string | string[], defaultValue: DefaultValue, options: TOpt & $Dictionary]
768
- | _KeyAndOptions<Key, $NoInfer<Ret>, ActualOptions>
855
+ | _KeyAndOptions<
856
+ Key,
857
+ $NoInfer<
858
+ _CheckedReturn<Ret, Ns, AppendKeyPrefix<Key, EffectiveKPrefix<KPrefix, TOpt>>, TOpt>
859
+ >,
860
+ ActualOptions
861
+ >
769
862
  ): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, DefaultValue>, TOpt>;
770
863
  }
771
864
 
772
- type TFunctionSignature<
865
+ export type TFunctionSignature<
773
866
  Ns extends Namespace = DefaultNamespace,
774
867
  KPrefix = undefined,
775
868
  > = _EnableSelector extends true | 'optimize' | 'strict'
@@ -783,7 +876,20 @@ export interface TFunction<
783
876
  KPrefix = undefined,
784
877
  > extends TFunctionSignature<Ns, KPrefix> {}
785
878
 
786
- export type KeyPrefix<Ns extends Namespace> = ResourceKeys<true>[$FirstNamespace<Ns>] | undefined;
879
+ export type KeyPrefix<Ns extends Namespace> =
880
+ | (TypeOptions['keySeparator'] extends false
881
+ ? _DotPrefixes<ResourceKeys<true>[$FirstNamespace<Ns>]>
882
+ : ResourceKeys<true>[$FirstNamespace<Ns>])
883
+ | undefined;
884
+
885
+ /**
886
+ * With `keySeparator: false` a key prefix is joined with `.` and the result is looked up as a flat
887
+ * key, so the prefixes are the parts of the flat keys before a `.`: `'a'` and `'a.b'` for `'a.b.c'`.
888
+ */
889
+ type _DotPrefixes<Keys> = string extends Keys ? string : _DotPrefixesOf<Keys>;
890
+ type _DotPrefixesOf<Key> = Key extends `${infer Head}.${infer Tail}`
891
+ ? Head | `${Head}.${_DotPrefixesOf<Tail>}`
892
+ : never;
787
893
 
788
894
  /**
789
895
  * The keys of `ParseKeys<Ns, {}, KPrefix>` that `t()` takes without options: their string has no
@@ -802,11 +908,9 @@ export type ParseKeysWithoutVariables<
802
908
  KPrefix = undefined,
803
909
  > = _KeysWithoutVariables<ParseKeys<Ns, {}, KPrefix>, Ns, KPrefix>;
804
910
 
805
- // resolved with `count`, so a plural key is checked against its plural forms
911
+ // a plural key without a value of its own is checked against its plural forms
806
912
  type _KeysWithoutVariables<Key, Ns extends Namespace, KPrefix> = Key extends string
807
- ? {} extends InterpolationMap<
808
- TFunctionReturn<Ns, AppendKeyPrefix<Key, KPrefix>, { count: number }>
809
- >
913
+ ? {} extends InterpolationMap<_CheckedValue<Ns, AppendKeyPrefix<Key, KPrefix>, {}>>
810
914
  ? Key
811
915
  : never
812
916
  : never;
@@ -855,7 +959,7 @@ export type SelectorParam<Ns extends Namespace = DefaultNamespace, KPrefix = und
855
959
 
856
960
  declare const $PluralBrand: unique symbol;
857
961
  /** Marks a value as coming from a plural-form key, requiring `count` in the selector options. */
858
- type PluralValue<T extends string> = T & { readonly [$PluralBrand]: typeof $PluralBrand };
962
+ export type PluralValue<T extends string> = T & { readonly [$PluralBrand]: typeof $PluralBrand };
859
963
 
860
964
  declare const $SelectorKeyBrand: unique symbol;
861
965
  /**
@@ -879,7 +983,7 @@ export type KeyFromSelectorFn = <
879
983
  ) => SelectorKey;
880
984
 
881
985
  /** Recursively strips the {@link PluralValue} brand from a type (handles nested objects for `returnObjects`). */
882
- type DeepUnwrapPlural<T> =
986
+ export type DeepUnwrapPlural<T> =
883
987
  T extends PluralValue<infer U>
884
988
  ? U
885
989
  : T extends readonly any[]
@@ -888,9 +992,9 @@ type DeepUnwrapPlural<T> =
888
992
  ? { [K in keyof T]: DeepUnwrapPlural<T[K]> }
889
993
  : T;
890
994
 
891
- type NsArg<Ns extends Namespace> = Ns[number] | readonly Ns[number][];
995
+ export type NsArg<Ns extends Namespace> = Ns[number] | readonly Ns[number][];
892
996
 
893
- interface TFunctionSelector<Ns extends Namespace, KPrefix, Source> extends Branded<Ns> {
997
+ export interface TFunctionSelector<Ns extends Namespace, KPrefix, Source> extends Branded<Ns> {
894
998
  // ── Pre-computed key(s) from keyFromSelector ────────────────────────────────
895
999
  // Accepts a branded `SelectorKey` (or array of them) produced by `keyFromSelector`.
896
1000
  // Return-type precision is traded for the flexibility of decoupled key creation.
@@ -1024,12 +1128,12 @@ interface TFunctionSelector<Ns extends Namespace, KPrefix, Source> extends Brand
1024
1128
  ): SelectorReturn<ReturnType<Fn>, Opts>;
1025
1129
  }
1026
1130
 
1027
- interface SelectorOptions<Ns = Namespace>
1131
+ export interface SelectorOptions<Ns = Namespace>
1028
1132
  extends Omit<TOptionsBase, 'ns' | 'nsSeparator'>, $Dictionary {
1029
1133
  ns?: Ns;
1030
1134
  }
1031
1135
 
1032
- type SelectorReturn<
1136
+ export type SelectorReturn<
1033
1137
  Target,
1034
1138
  Opts extends { defaultValue?: unknown; returnObjects?: boolean },
1035
1139
  DV = Opts['defaultValue'],
@@ -1042,10 +1146,10 @@ export interface SelectorFn<Source, Target, Opts extends SelectorOptions<unknown
1042
1146
  (translations: Select<Source, Opts['context']>): Target;
1043
1147
  }
1044
1148
 
1045
- type ApplyKeyPrefix<
1149
+ export type ApplyKeyPrefix<
1046
1150
  T extends [any],
1047
1151
  KPrefix,
1048
- > = KPrefix extends `${infer Head}${_KeySeparator}${infer Tail}`
1152
+ > = KPrefix extends `${infer Head}${_KeyPrefixSeparator}${infer Tail}`
1049
1153
  ? ApplyKeyPrefix<[T[0][Head]], Tail>
1050
1154
  : T[0][KPrefix & string];
1051
1155
 
@@ -1064,7 +1168,7 @@ export type ConstrainTarget<Opts extends SelectorOptions<any>> = _ReturnObjects
1064
1168
  ? unknown
1065
1169
  : string;
1066
1170
 
1067
- type ProcessReturnValue<Target, DefaultValue> = $Turtles extends Target
1171
+ export type ProcessReturnValue<Target, DefaultValue> = $Turtles extends Target
1068
1172
  ? string
1069
1173
  : [DefaultValue] extends [never]
1070
1174
  ? Target
@@ -1072,12 +1176,12 @@ type ProcessReturnValue<Target, DefaultValue> = $Turtles extends Target
1072
1176
  ? Target
1073
1177
  : Target | DefaultValue;
1074
1178
 
1075
- type PickNamespaces<T, K extends keyof any> = {
1179
+ export type PickNamespaces<T, K extends keyof any> = {
1076
1180
  [P in K as P extends keyof T ? P : never]: T[P & keyof T];
1077
1181
  };
1078
1182
 
1079
1183
  /** Extracts the sub-tree returned by a selector function used as keyPrefix. */
1080
- type SelectorReturnSource<KPrefix, Fallback> = KPrefix extends (...args: any[]) => infer R
1184
+ export type SelectorReturnSource<KPrefix, Fallback> = KPrefix extends (...args: any[]) => infer R
1081
1185
  ? R extends object
1082
1186
  ? R
1083
1187
  : Fallback
@@ -1094,7 +1198,7 @@ export type GetSource<Ns extends Namespace, KPrefix, Res = NsResource<Ns>> = KPr
1094
1198
  ? Res
1095
1199
  : ApplyKeyPrefix<[Res], KPrefix>;
1096
1200
 
1097
- type Select<T, Context> = $IsResourcesDefined extends false
1201
+ export type Select<T, Context> = $IsResourcesDefined extends false
1098
1202
  ? $Turtles
1099
1203
  : [_EnableSelector] extends ['optimize']
1100
1204
  ? T
@@ -1207,13 +1311,13 @@ type _IsContextualKey<T, K extends string> =
1207
1311
  * and context variants that exist on a single element are invisible, which
1208
1312
  * produced partial element unions for `returnObjects` + `context` (#2398).
1209
1313
  */
1210
- type FilterKeys<T, Context> = [T] extends [readonly any[]]
1314
+ export type FilterKeys<T, Context> = [T] extends [readonly any[]]
1211
1315
  ? { [I in keyof T]: FilterKeys<T[I], Context> }
1212
1316
  : T extends any
1213
1317
  ? FilterKeysObject<T, Context>
1214
1318
  : never;
1215
1319
 
1216
- type FilterKeysObject<T, Context> = {
1320
+ export type FilterKeysObject<T, Context> = {
1217
1321
  // Mapped type 1: object-valued keys (recurse) + plain leaf keys (non-plural, non-context)
1218
1322
  [
1219
1323
  K in keyof T as [keyof T[K]] extends [never]
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- /* eslint no-var: 0 */
2
- var main = require('./dist/cjs/i18next.js');
3
-
4
- module.exports = main;
5
- module.exports.default = main;