@@ -9,13 +9,13 @@ type GetParamKeys<TTranslation extends string> = TTranslation extends ""
99const translate = <
1010 TTranslations extends Record < string , string > ,
1111 TKey extends keyof TTranslations ,
12- TComputedArgs extends string [ ] = GetParamKeys < TTranslations [ TKey ] > ,
12+ TParamKeys extends string [ ] = GetParamKeys < TTranslations [ TKey ] > ,
1313> (
1414 translations : TTranslations ,
1515 key : TKey ,
16- ...args : TComputedArgs extends [ ]
16+ ...args : TParamKeys extends [ ]
1717 ? [ ]
18- : [ params : Record < TComputedArgs [ number ] , string > ]
18+ : [ params : Record < TParamKeys [ number ] , string > ]
1919) => {
2020 const translation = translations [ key ] ;
2121 const params : any = args [ 0 ] || { } ;
@@ -26,7 +26,7 @@ const translate = <
2626// TESTS
2727
2828const translations = {
29- title : "Hello, {firstName} {surname }!" ,
29+ title : "Hello, {name }!" ,
3030 subtitle : "You have {count} unread messages." ,
3131 button : "Click me!" ,
3232} as const ;
@@ -39,7 +39,7 @@ it("Should translate a translation without parameters", () => {
3939
4040it ( "Should translate a translation WITH parameters" , ( ) => {
4141 const subtitle = translate ( translations , "subtitle" , {
42- count : "2 " ,
42+ count : "123123 " ,
4343 } ) ;
4444
4545 expect ( subtitle ) . toEqual ( "You have 2 unread messages." ) ;
0 commit comments