How to deal with nested objects which might be string or undefined in a clean way?
Typescript has supported optional chaining for a while. To do this concisely and avoid the somewhat inelegant as string type assertion, extract the possibly nested value into a variable, then check its typeof against string:
const instanceId = data.InstanceStatuses?.[0].InstanceId;
if (typeof instanceId === 'string') {
  instanceIds.push(instanceId);
}

This way, instanceId will be either the nested value, or, if InstanceStatuses doesn't exist, it'll be undefined. So, it'll only push to the array if the nested value exists and the value is a string.