Currently, I have a response that I am retrieving from:
data?.currentOrganization?.onboardingSteps?
. It is possible for data, currentOrganization, and onboardingSteps to be null. My goal is to create a variable like this:
const hasSteps = data?.currentOrganization?.onboardingSteps?.length > 0;
My expectation was that hasValue would be false if any of the fields were null or if there were less than 1 step. However, I encountered the TypeScript error: Object is possibly 'undefined'
.
To work around this issue, I currently have:
const hasSteps =
data?.currentOrganization?.onboardingSteps != null &&
data?.currentOrganization?.onboardingSteps?.length > 0;
Although it works, I find this approach overly verbose. Is there a more elegant alternative solution available?