react-i18next 11.11.3 → 11.11.4
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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/ts4.1/index.d.ts +26 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### 11.11.4
|
|
2
|
+
|
|
3
|
+
- typescript: add returnNull and returnEptyString options to TypeOptions interface [1341](https://github.com/i18next/react-i18next/pull/1341)
|
|
4
|
+
|
|
1
5
|
### 11.11.3
|
|
2
6
|
|
|
3
7
|
- Trans: parse first, then interpolate [1345](https://github.com/i18next/react-i18next/pull/1345)
|
package/package.json
CHANGED
package/ts4.1/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ type Subtract<T extends K, K> = Omit<T, keyof K>;
|
|
|
26
26
|
*/
|
|
27
27
|
export interface Resources {}
|
|
28
28
|
/**
|
|
29
|
-
* This interface can be augmented by users to add types to `react-i18next`. It accepts a `defaultNS` and `
|
|
29
|
+
* This interface can be augmented by users to add types to `react-i18next`. It accepts a `defaultNS`, `resources`, `returnNull` and `returnEmptyString` properties.
|
|
30
30
|
*
|
|
31
31
|
* Usage:
|
|
32
32
|
* ```ts
|
|
@@ -35,6 +35,8 @@ export interface Resources {}
|
|
|
35
35
|
* declare module 'react-i18next' {
|
|
36
36
|
* interface CustomTypeOptions {
|
|
37
37
|
* defaultNS: 'custom';
|
|
38
|
+
* returnNull: false,
|
|
39
|
+
* returnEmptyString: false,
|
|
38
40
|
* resources: {
|
|
39
41
|
* custom: {
|
|
40
42
|
* foo: 'foo';
|
|
@@ -50,6 +52,8 @@ type MergeBy<T, K> = Omit<T, keyof K> & K;
|
|
|
50
52
|
|
|
51
53
|
type TypeOptions = MergeBy<
|
|
52
54
|
{
|
|
55
|
+
returnNull: true;
|
|
56
|
+
returnEmptyString: true;
|
|
53
57
|
defaultNS: 'translation';
|
|
54
58
|
resources: Resources;
|
|
55
59
|
},
|
|
@@ -111,12 +115,32 @@ type NormalizeMulti<T, U extends keyof T, L = LastOf<U>> = L extends U
|
|
|
111
115
|
? AppendNS<L, Normalize<T[L]>> | NormalizeMulti<T, Exclude<U, L>>
|
|
112
116
|
: never;
|
|
113
117
|
|
|
118
|
+
type CustomTypeParameters = {
|
|
119
|
+
returnNull?: boolean;
|
|
120
|
+
returnEmptyString?: boolean;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type TypeOptionsFallback<TranslationValue, Option, MatchingValue> = Option extends false
|
|
124
|
+
? TranslationValue extends MatchingValue
|
|
125
|
+
? string
|
|
126
|
+
: TranslationValue
|
|
127
|
+
: TranslationValue;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if user has enabled `returnEmptyString` and `returnNull` options to retrieve correct values.
|
|
131
|
+
*/
|
|
132
|
+
export type NormalizeByTypeOptions<
|
|
133
|
+
TranslationValue,
|
|
134
|
+
Options extends CustomTypeParameters = TypeOptions,
|
|
135
|
+
R = TypeOptionsFallback<TranslationValue, Options['returnEmptyString'], ''>
|
|
136
|
+
> = TypeOptionsFallback<R, Options['returnNull'], null>;
|
|
137
|
+
|
|
114
138
|
type NormalizeReturn<T, V> = V extends `${infer K}.${infer R}`
|
|
115
139
|
? K extends keyof T
|
|
116
140
|
? NormalizeReturn<T[K], R>
|
|
117
141
|
: never
|
|
118
142
|
: V extends keyof T
|
|
119
|
-
? T[V]
|
|
143
|
+
? NormalizeByTypeOptions<T[V]>
|
|
120
144
|
: never;
|
|
121
145
|
|
|
122
146
|
type NormalizeMultiReturn<T, V> = V extends `${infer N}:${infer R}`
|