typeof ... === "undefined"
check on mapped object member doesn't narrow correctly, for only some purposes
#52440
Labels
Milestone
Bug Report
🔎 Search Terms
undefined type guard narrowing fails
🕗 Version & Regression Information
typeof ... === "undefined"
check on discriminated union ofundefined
and object type doesn't narrow correctly #50340, which @a-tarasyuk may have fixed in fix(50340): typeof ... === "undefined" check on discriminated union of undefined and object type doesn't narrow correctly #50344 (Aug. 31 ’22), but I’m still seeing the issue on the latest nightly (v5.0.0-dev.20230126) so I don't think it's a duplicate.typeof
and optional chaining does not work specifically with a union containingboolean
unless wrapped in parentheses #51700 fixed in Fix narrowing bytypeof
applied to discriminant property #51720 (Dec. 5 '22) as that focuses on the optional chaining operator.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Error
'attributeValue' is possibly 'undefined'
(for the purposes of a for loop but not for the purposes of a function call) inside a type-guard conditional checking for undefined, where attributeValue is a constant originally copied from a mapped object type.🙂 Expected behavior
attributeValue
can be undefined within the two immediate children lines in the conditional (function call and for loop).typeof attributeValue !== 'undefined'
andattributeValue !== undefined
.The text was updated successfully, but these errors were encountered: