-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
I encountered a 'not assignable type' error when I turned on the 'noUncheckedIndexedAccess' option. #54353
Comments
It's working as intended / a known design limitation with many many issues opened already, and it really needs to be added to the FAQ. Indexed access is not narrowed, unless the key is a literal. |
Tracked at #10530 |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
π Version & Regression Information
Typescript version that I tried: 4.9.5, 5.0.4, 5.1.0-beta
β― Playground Link
Make it sure that the "noUncheckedIndexedAccess" option is turned on.
Playground link
π» Code
π Actual behavior
Type guard doesn't work properly and typescript occurs not assignable type error when using the "noUncheckedIndexedAccess" option.
π Expected behavior
The type guard works properly even the "noUncheckedIndexedAccess" option is turned on.
For example,
fruits[fruitName]
should be 'string', not 'string | undefined'The text was updated successfully, but these errors were encountered: