Guarding against object value not being undefined fails when object value is typed with Partial<T> | undefined
#53148
Labels
Duplicate
An existing issue was already created
Bug Report
🔎 Search Terms
Partial<T> | undefined
🕗 Version & Regression Information
I reproduced this on TS4.5, 4.8, 4.9, and 5.1.0-dev.20230306
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.1.0-dev.20230306#code/JYOwLgpgTgZghgYwgAgCoQM5mQbwFDLIBGANnABYBcyWUoA5gNwHIwD2b1tDzAvnnlCRYiFAjbg4oaLhYBtANYQAnlzB0Q9ALrUACnChhgcEgB50WAHzIAPsgCuIACYQY0p3wHiQWZGyIAVtTeYFIgMgC8soRw1PiEhKQU1ABEcCkANCyE7JzIKUSZLLxZvMx43r7qyqjkmChRcmmZ+YVa5exQyAAUldhgbKhQyn4wyNW19QCU0cjAY93+AXIDQ8payACEUY4ubuFOM-EJlWwkEAB0JGz0i4Erg8NaF0nkU8yE-PxAA
💻 Code
🙁 Actual behavior
I specifically check if
obj[toTry]
is not undefined but TS still throws an error thatobj[toTry]
is potentially undefined. I suspect this is becausePartial<T>
is a superset ofundefined
.🙂 Expected behavior
I want TS to not throw an error that
obj[toTry]
is undefined.The text was updated successfully, but these errors were encountered: