-
Notifications
You must be signed in to change notification settings - Fork 12.8k
narrowing object by property doesn't work if key isn't a const
#51368
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
Comments
I managed to minify this issue a little bit, take a look below: declare const data: {
a?: number
}
if (data.a === undefined) throw "up"
const a = data['a' as 'a']
// ^? const a: number | undefined
const b = data['a']
// ^? const b: number |
Duplicate of #10530. Only certain patterns of property access induce narrowing, specifically only the forms |
the example in that issue seems to have been fixed ages ago #10530 (comment) |
Yeah, |
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
narrow property const
π Version & Regression Information
4.9.0-dev.20221025
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
data[key]
isnumber | undefined
π Expected behavior
data[key]
is narrowed tonumber
The text was updated successfully, but these errors were encountered: