Skip to content

Type error on template literal with expression on Typescript 4.2 #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elgorditosalsero opened this issue May 17, 2021 · 5 comments
Closed
Assignees

Comments

@elgorditosalsero
Copy link

🐛 Bug Report

On Typescript 4.2.x the typed t function throw a type error when using template literal with an expression.
The doc says that's handled by TS 4.2.x and the workaround of as const is required only in TS 4.1.

ts

To Reproduce

  1. Follow the guide for TS support on a project with TS 4.2.x.
  2. Use an expression inside the t function with a template literal
t(`activities:bottomSheets.assumption.title.${activity._type}`)

Expected behavior

TS should not throw the error :)

Your Environment

  • runtime version: Node 15.13.0, React Native 0.64, TS 4.2.4
  • i18next version: 20.2.2
  • os: Mac
@pedrodurek
Copy link
Member

Hey @elgorditosalsero, typescript team ended up reverting the Template Literal Inference feature. You can find more info here.
You can see the discussion here as well: microsoft/TypeScript#42589, microsoft/TypeScript#41891
So that, as const is still needed 😞 . I'll update the document.

@pedrodurek
Copy link
Member

I will let you know if anything changes

@elgorditosalsero
Copy link
Author

Hi @pedrodurek, thx for the info, will check the issues!

Btw, I'm still having the error also with as const as the attached screenshots.

Schermata 2021-05-17 alle 17 01 57
Schermata 2021-05-17 alle 17 02 12

@pedrodurek
Copy link
Member

Hey @elgorditosalsero, It seems to be missing some keys, for example:

{
  key: {
   a: 'a',
   b: 'b',
  }
}

c is missing here.

type Foo = 'a' | 'b' | 'c';
const foo: Foo = 'b';
...
t(`key.${foo}`);

@elgorditosalsero
Copy link
Author

@pedrodurek Thx for the tips, my fault on the translation file!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants