Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React i18n - "t" function doesn't accept string variables (typescript)? "No overload matches this call"

anyone familiar with this error: [code with error message][1] [1]: https://i.sstatic.net/SbJvu.png

{t(`${settingType}` as const)}

error:

No overload matches this call.
  Overload 1 of 2, '(key: TemplateStringsArray | Normalize<{

Thanks :)

like image 957
Adri Avatar asked Dec 30 '25 13:12

Adri


2 Answers

Solution: change t(str) to

t(str as unknown as TemplateStringsArray)

I personally created a helper function to do so, which I recommend.

like image 60
Adri Avatar answered Jan 01 '26 09:01

Adri


I'm facing the same problem and Adri's answer helped me.

If you want, this is the function I've done:

export const normalizeKey = (key: string) => key as unknown as TemplateStringsArray;
like image 24
Rui Araújo Avatar answered Jan 01 '26 08:01

Rui Araújo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!