We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TS2801
Playground link with relevant code
const a: { [key: string]: Promise<string> } = {} if (a['a']) { }
This condition will always return true since this 'Promise' is always defined.
No error.
The text was updated successfully, but these errors were encountered:
You want to enable noUncheckedIndexedAccess. Without this compiler flag it's assumed that indexed access returns a valid value.
noUncheckedIndexedAccess
Sorry, something went wrong.
Unfortunately, due to #10530 noUncheckedIndexedAccess is not handy here:
if (a['a']) { a['a'] // Promise<string> | undefined }
And I assume it will be even harder to narrow for index value 'a' to be variable and not literal
'a'
So, the workaround here is to use in instead of index access:
in
if ('a' in a) { a['a'] // Promise<string> }
No branches or pull requests
Bug Report
π Search Terms
TS2801
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
This condition will always return true since this 'Promise' is always defined.
π Expected behavior
No error.
The text was updated successfully, but these errors were encountered: