@@ -9,13 +9,13 @@ type GetParamKeys<TTranslation extends string> = TTranslation extends ""
9
9
const translate = <
10
10
TTranslations extends Record < string , string > ,
11
11
TKey extends keyof TTranslations ,
12
- TComputedArgs extends string [ ] = GetParamKeys < TTranslations [ TKey ] > ,
12
+ TParamKeys extends string [ ] = GetParamKeys < TTranslations [ TKey ] > ,
13
13
> (
14
14
translations : TTranslations ,
15
15
key : TKey ,
16
- ...args : TComputedArgs extends [ ]
16
+ ...args : TParamKeys extends [ ]
17
17
? [ ]
18
- : [ params : Record < TComputedArgs [ number ] , string > ]
18
+ : [ params : Record < TParamKeys [ number ] , string > ]
19
19
) => {
20
20
const translation = translations [ key ] ;
21
21
const params : any = args [ 0 ] || { } ;
@@ -26,7 +26,7 @@ const translate = <
26
26
// TESTS
27
27
28
28
const translations = {
29
- title : "Hello, {firstName} {surname }!" ,
29
+ title : "Hello, {name }!" ,
30
30
subtitle : "You have {count} unread messages." ,
31
31
button : "Click me!" ,
32
32
} as const ;
@@ -39,7 +39,7 @@ it("Should translate a translation without parameters", () => {
39
39
40
40
it ( "Should translate a translation WITH parameters" , ( ) => {
41
41
const subtitle = translate ( translations , "subtitle" , {
42
- count : "2 " ,
42
+ count : "123123 " ,
43
43
} ) ;
44
44
45
45
expect ( subtitle ) . toEqual ( "You have 2 unread messages." ) ;
0 commit comments