function func1(bla) {
var deferred;
if (condition) {
bla.forEach(function (val) {
deferred = $q.all(func2(val));
})
} else {
deferred = func2(bla);
}
return deferred;
}
function func2(bla) {
var defer = $q.defer();
if (cond2) {
defer.resolve(...);
} else {
defer.reject(...);
}
return defer.promise;
}
function func1(bla: any | any[]): Promise<any> {
if (bla instanceof Array) {
return Promise.all(bla.map(func2));
}
return func2(bla);
}
function func2(bla: any): Promise<any> {
return new Promise((resolve, reject) => {
if (cond2) {
resolve(...);
} else {
reject(...);
}
});
}