question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to initialize TFunction for testing after latest version

See original GitHub issue

šŸ› Bug Report

Hi. I’ve initialized TFunction in my tests before i18next v22 and i18next v12, but I’m not able to do that after the upgrade.

To Reproduce

Code before the upgrade

import { TFunction } from 'react-i18next';

import { translationResources } from '../../constants';

const translation: { [key: string]: string } = translationResources.fi.translation;

const t: TFunction<'translation', undefined> = (str: string) => translation[str];

Code after the upgrade

import { TFunction } from 'i18next';

import { translationResources } from '../../constants';

const translation: { [key: string]: string } = translationResources.fi.translation;

const t: TFunction<'translation', undefined> = (str: string) => translation[str];

The error

Type '(str: string) => string' is not assignable to type 'TFunction<"translation", undefined>'.
  Type 'string' is not assignable to type 'TFunctionDetailedResult<any>'.

Expected behavior

I expect to be able to initialize TFunction

Your Environment

  • runtime version: node v16
  • i18next version: 22.0.2
  • os: macOS
  • typescript: 4.7.4

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pedrodurekcommented, Oct 29, 2022

That’s a function overload limitation because TFunction can have multiple shapes, but it can’t determine the right one if it’s not used on the actual t function. There are a few things that I can do to remove ā€œweightā€ from the TFunction and will fix your problem, I’ll keep you posted.

1reaction
adraicommented, Oct 27, 2022

Can you try with 22.0.3?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to initialize DB for every test method in spring boot
I'm trying to set-up an integration test scenario for spring boot where a fresh H2 database is createdĀ ...
Read more >
TestNG fail if there was some exception in test class initialization
Hi! There is a bug in TestNG 5.13.1 (earler versions seems also affected). In case if test class initialization failed, TestNG shows error...
Read more >
"Unable to initialize database" error when creating a new SQL ...
Unable to initialize database "twjcq" with schema "WJCQuest" version 42. Reason: SQLExecute: RETCODE=-1, State=37000, Native Error=156 SQLĀ ...
Read more >
[FIXED] 'DirectX Failed to Initialize. Please Install the Correct ...
1. How to Fix the ā€œDirectX Failed to Initializeā€ Error. 2. Update DirectX. 3. Upgrade the DirectX Suite.
Read more >
3000s - Application Error Messages
Error number Error message Additional info and instruction 3093 File name missing error Contact Pearson Support. 3105 You must use the TestNav app to take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found