You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I stumbled upon this weird behavior that I couldn't wrap my head around. I searched with "object is possibly undefined bug typescript github" on Google and went through the first 5-6 bugs but didn't find any which quite resembled this case. I am new to Typescript so it is entirely possible that this is expected behavior. If that's the case I apologize and humbly ask for an explanation. Thanks!
🔎 Search Terms
"Object is possibly undefined"
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about "common-bugs-that-arent-bugs."
'result.optionalParam' is possibly 'undefined' error on the last line.
🙂 Expected behavior
Code compiles without any errors. optionalParam is typed as though it can be undefined however, in the example above result.optionalParam is clearly defined. There is no code in between result initialization and result.optionalParam which could set it to undefined. So, this should've worked I think.
The text was updated successfully, but these errors were encountered:
Hi Martin, thanks for pointing me to the duplicate. I've read through that and #47920 several times over the past 2 days but I couldn't make sense of it. The discussion at #47920 is unfortunately a bit too complicated for me. Could you please let me know (or point me to) if this functionality should be implemented some other way and/or is this not supported by Typescript yet?
Bug Report
Hi, I stumbled upon this weird behavior that I couldn't wrap my head around. I searched with "object is possibly undefined bug typescript github" on Google and went through the first 5-6 bugs but didn't find any which quite resembled this case. I am new to Typescript so it is entirely possible that this is expected behavior. If that's the case I apologize and humbly ask for an explanation. Thanks!
🔎 Search Terms
"Object is possibly undefined"
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
'result.optionalParam' is possibly 'undefined'
error on the last line.🙂 Expected behavior
Code compiles without any errors.
optionalParam
is typed as though it can beundefined
however, in the example aboveresult.optionalParam
is clearly defined. There is no code in betweenresult
initialization andresult.optionalParam
which could set it toundefined
. So, this should've worked I think.The text was updated successfully, but these errors were encountered: