for the following snippet of code, ts complains that “object is possibly null” with a red underline just below “rawMQTTTopicsResults[topic].timestamp < staleTimestamp.toString()”
for (const topic of Object.keys(rawMQTTTopicsResults)) {
let stale: boolean = true
if (rawMQTTTopicsResults[topic] && rawMQTTTopicsResults[topic].timestamp !== null){
stale = rawMQTTTopicsResults[topic].timestamp < staleTimestamp.toString()
}
resultsWithStale[topic] = {
...rawMQTTTopicsResults[topic],
stale: stale
};
}
and here is the type for “rawMQTTTopicsResults”
const rawMQTTTopicsResults: Record<string, {
timestamp: string | null;
value: string | number | boolean | null;
}>
it is worth noting that my vs-code compiler does not indicate this error, it only appears when building.