Adri
Adri

Reputation: 162

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 :)

Upvotes: 3

Views: 4239

Answers (2)

Adri
Adri

Reputation: 162

Solution: change t(str) to

t(str as unknown as TemplateStringsArray)

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

Upvotes: 7

Rui Ara&#250;jo
Rui Ara&#250;jo

Reputation: 81

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;

Upvotes: 2

Related Questions