I have such code:
if (action?.notificationKey && state.notifications[action.notificationKey]) {
delete state.notifications[action.notificationKey];
}
which does not satisfy me, because action.notificationKey can have 0 value and optional chaining condition is not fulfilled.
refactoring to:
if ("notificationKey" in action && state.notifications[action.notificationKey]) {
delete state.notifications[action.notificationKey];
}
does not satisfy TS, and it underlines second condition as "TS2538: Type 'undefined' cannot be used as an index type"
how else I can check property with possible zero value existence?
edit: modified my question as I pasted previous code version, added optional chaining as it is currently