i18next: TFuncKey type breaks when used in Record and Map types

πŸ› Bug Report

Use TFuncKey in a Record or Map type, and the outputted type from t(recordOrMapKey) will not be string.

To Reproduce

https://codesandbox.io/p/sandbox/elastic-burnell-wm183x?file=%2Fsrc%2FApp.tsx

Notice that there are TS errors at the bottom of <Component> and <App>, and that t(recordKey) and t(mapKey) equal 'string | { bar: string; }'.

Two curious observations:

  1. Commenting out the nested foo string causes all TS errors to go away.
  2. t(key) also errors out when used in a function Foo() {} component instead of a const Foo = () => {} component. Not sure what the difference is there.

Expected behavior

The TS type from t(recordKey) and t(mapKey) should equal string.

Your Environment

  • β€œi18next”: β€œ^22.4.13”
  • β€œreact”: β€œ^18.2.0”
  • β€œreact-dom”: β€œ^18.2.0”
  • β€œreact-i18next”: β€œ^12.2.0”
  • β€œ@types/i18n-js”: β€œ^3.8.2”
  • β€œ@types/react”: β€œ^18.0.15”
  • β€œ@types/react-dom”: β€œ^18.0.6”
  • β€œtypescript”: β€œ^4.6.4”

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments