Looking for a way to determine if a function parameter is an array or not, and then process it accordingly. If the parameter is not an array, convert it into an array before performing the desired function.
For example:
interface employee {
first: string,
last: string
}
function updateEmployees (emp: employee | employee[]) {
let employees = [];
if (emp instanceof Array) employees = [emp];
else employees = emp;
employees.forEach(function(e){
return 'something'
})
}
While this logic seems correct, it's raising a warning stating
Type 'employee' is not assignable to type 'any[]'. Property 'length' is missing in type 'employee'.