@@ -6,19 +6,16 @@ type GetParamKeys<TTranslation extends string> = TTranslation extends ""
6
6
? [ Param , ...GetParamKeys < Tail > ]
7
7
: [ ] ;
8
8
9
- type GetParamKeysAsUnion < TTranslation extends string > =
10
- GetParamKeys < TTranslation > [ number ] ;
11
-
12
9
const translate = <
13
10
TTranslations extends Record < string , string > ,
14
11
TKey extends keyof TTranslations ,
15
- TDynamicKeys = GetParamKeysAsUnion < TTranslations [ TKey ] > ,
12
+ TComputedArgs extends string [ ] = GetParamKeys < TTranslations [ TKey ] > ,
16
13
> (
17
14
translations : TTranslations ,
18
15
key : TKey ,
19
- ...args : [ TDynamicKeys ] extends [ never ]
16
+ ...args : TComputedArgs extends [ ]
20
17
? [ ]
21
- : [ dynamicArgs : Record < TDynamicKeys & string , string > ]
18
+ : [ params : Record < TComputedArgs [ number ] , string > ]
22
19
) => {
23
20
const translation = translations [ key ] ;
24
21
const params : any = args [ 0 ] || { } ;
@@ -29,7 +26,7 @@ const translate = <
29
26
// TESTS
30
27
31
28
const translations = {
32
- title : "Hello, {name }!" ,
29
+ title : "Hello, {firstName} {surname }!" ,
33
30
subtitle : "You have {count} unread messages." ,
34
31
button : "Click me!" ,
35
32
} as const ;
0 commit comments