I'm trying to find a way to check whether a function parameter is an array or not. If it is not, turn it into an array and perform a function on it, otherwise just perform a function on it.
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'
})
}
This seems like it would work to me but is throwing a warning of Type 'employee' is not assignable to type 'any[]'. Property 'length' is missing in type 'employee'.