I am struggling with a recurring "No best common type" error, even though I have assigned the function a 'any' type. I have also experimented with combinations of types like 'any|string', 'string|any'. . . Any help would be greatly appreciated.
export class TestClass {
gotCode: any;
constructor() {
this.gotCode = function(){
var codes = Lodash.compact(Lodash.map(Parse.User.current().get("blah"), function(n){
if(moment().isBefore(n.endDate) && moment().isAfter(n.startDate)){
return n;
}
}));
if (codes.length > 0){
return {endDate: Lodash.first(codes).endDate, codeId: Lodash.first(codes).objectId, consumerMatchingCardCash: Lodash.first(codes).consumerMatchingCardCash, codeName: Lodash.first(codes).codeName, consumerPercentIncreaseOnCashBack: Lodash.first(codes).consumerPercentIncreaseOnCashBack};
} else{
return "No Codes";
}
}();
}
}
After reviewing the following pages: Type inference with union types - No best common type exists
Angular2: No best common type exists among return expressions
No best common type exists among return expressions