React-i18next: (typescript) Template literals no longer work post 11.8.0

Created on 7 Dec 2020  路  8Comments  路  Source: i18next/react-i18next

Example usage

const [ t ]      = useTranslation();

return <>{t`Hello`}</>

Worked in react-i18next v 11.7.4, but not 11.8.0, now errors with

No overload matches this call.
  Overload 1 of 2, '(key: never, options?: string | TOptions<StringMap> | undefined): never', gave the following error.
    Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'never'.
  Overload 2 of 2, '(key: never, defaultValue?: string | undefined, options?: string | TOptions<StringMap> | undefined): never', gave the following error.
    Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'never'.  TS2769

Most helpful comment

Hey @onionhammer, It should be fixed now. I added the support to template string back, but unfortunately TemplateStringsArray doesn't support generics yet (https://github.com/microsoft/TypeScript/issues/33304), so this PR https://github.com/i18next/react-i18next/pull/1193, which types all keys from t function won't work for you.

@tigerabrodi you were right! This was a different issue indeed, which was returning the same error.

All 8 comments

Seems to be something that happened after TypeScript PR. Any ideas @pedrodurek ?

it is the same error #1212

@pedrodurek I should defo debounce my questions sometimes haha :man_facepalming: :joy:

Hey @onionhammer, It should be fixed now. I added the support to template string back, but unfortunately TemplateStringsArray doesn't support generics yet (https://github.com/microsoft/TypeScript/issues/33304), so this PR https://github.com/i18next/react-i18next/pull/1193, which types all keys from t function won't work for you.

@tigerabrodi you were right! This was a different issue indeed, which was returning the same error.

Hey @onionhammer, can we close this one?

@pedrodurek seems like this leads to another breaking change/or perhaps bug; now the result of

t`Something`

is not a string, it's a TFunction, so it cant be passed as a string to props.

Ohh yeah, it's been handled here: https://github.com/i18next/react-i18next/issues/1217

Closing in favor if #1217

Was this page helpful?
0 / 5 - 0 ratings