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:
- Commenting out the nested
foo
string causes all TS errors to go away. t(key)
also errors out when used in afunction Foo() {}
component instead of aconst 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
- types: default values for ParseKeys arguments #1944 — committed to i18next/i18next by adrai a year ago
@pedrodurek just done so: https://github.com/i18next/i18next/commit/18ce83f7f5a28548cef107c5cad5434ef5033a60