[Vuejs]-Object possibly undefined

1👍

You will need a predicate as your return type

function checkLineCharts(
  lineChart: InstanceType<typeof chart> | undefined,
): lineChart is InstanceType<typeof chart>{
  if (!lineChart) {
    console.warn(
      "No linechart found. Probably navigated away before this function ended"
    );
    return false;
  }
  return true;
}

Btw, multiple predicates aren’t possible, so you’ll need 2 separate functions.

Leave a comment