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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not existing context not detected as type error if covered by string union #2172
Comments
Honestly I have no idea on how to fix this 馃槩. As a workaround you can use |
@marcalexiei enums actually have the same problem, I've updated my reproduction. But basically enums only work if you assign a known value, but if you assign something which could be any of the enum values it will also happily accept it instead of correctly determining a type error. |
Gotcha, so it's related, if not the same, issue of the string union. |
I are also seeing this bug... i'll try to fix it. |
I'm not even sure if this isn't a feature gap in typescript itself and might warrant to create a issue in the typescript repo. But haven't found the time yet to try to create a minimal reproduction. |
Not sure if this maybe breaks something else, but the following code works for my project:
i18next+23.11.3.patch
@marcalexiei can you maybe sanity check this approach if it makes sense? EDIT: just cloned i18next and ran the typescript tests and seems to be working for those as well. |
Thanks for spend your time taking a look at this @stefan-schweiger! 馃
Open a PR to see if your patch affects current tested scenarios
A PR is a better place to discuss code changes. Another reason to open it 馃槄 FYI right now I don't have to perform a review, maybe in the next days. |
@marcalexiei created the PR let me know when you find the time to take a look. |
馃悰 Bug Report
I was told to move this issue here from the i18next/react-i18next#1743 repo.
When you use a string union as the context parameter it's possible to supply values for which a context does not exist and it does not result in an error. If you just use the plain string value or a const it works.
To Reproduce
A minimal reproducible example.
Expected behavior
String unions should be correctly detected as errors if they have cases which are not covered by the context.
Your Environment
The text was updated successfully, but these errors were encountered: