How to understand this ERROR?

How to understand this error?

The repeater works just fine, and is feeded by the result-items of a DB-Query. Is this ERROR neccessary?

let collectionData = await get_AllCollectionsData(); 
.then((res)=>{//console.log("RES-COLLECTIONS: ", res);
   if (res.items.length>0) {console.log("Collection-Data found!");
       let items = res.items; 
       return (items);
  }
  else {console.log("No Collection-Data found!"); return ([]);}
}).catch((err)=>{console.log(err);});

Hi Dima - @russian-dima ,

The error means that your function returns two possible types of values, the first type is any[ ] , which means an array of anything, this type of data is returned only if the results are more than 0 (according to your code), but what if the results are 0? In your if … else statement, the if returns the items ( any[ ] ), but you’re not returning anything in your else code block, which means the function will return void , or in other words, NOTHING , and obviously, you can’t assign null or undefined to the data property, which only accepts arrays, so the IDE is one step ahead of you, and is warning you about the possibility of returning something other than an array, it’s doing this so you pay attention and fix your function to avoid possible errors in the future.

Hope this helps~!
Ahmad

I have tried a buch of different code-variations but without any success.
The code is still working, but i want to get rid of the error-info.

but you’re not returning anything in your else code block, which means the function will return void , or in other words, NOTHING , and obviously, you can’t assign null or undefined to the data property,
Ok, changing my → else ← to …

return  [
   {
       "_id": "1",
       "firstName": "John",
       "lastName": "Doe",
       "image": "http://someImageUrl/john.jpg"
    },
    {
       "_id": "2",
       "firstName": "Jane",
       "lastName": "Doe",
       "image": "http://someImageUrl/jane.jpg"
    }
]

This is exact the value, what the repeater expects to be feeded with.
Example from REPEATER-API.

Now i have in both cases (if/else) the right prepared DATA for repeater to be feeded with. But still the same ERROR.

I think i missunderstand something. Could you make an example. What to fix exactly?

BTW: Putting the given results directly to repeater removes the error.

I am confused. :sweat_smile:

Damn! I got it!

While i was generating this post, i found the error causing code-part.
It was not the → ELSE ← statement, it was the → .catch() ← what caused the error.

But this is strange isn’t it? I do return anything in my → .catch()-part.
Deactivating the .catch()-part → resolves the issue.

A simple → [ ] ← is assingable as data to repeater.

Or another way to solve it…

.catch((err)=>{console.log(err); return [];});

But that’s kind of confusing. For me not logical.

Anyway → Deserves —>Best-Answer<— THANKS for TIP!

@russian-dima Sorry didn’t pay attention to the catch part once my eyes laid on the if … else section :joy: My answer applies to the catch section as well, adding another code block to the function will add another possibility, and in your case the cache wasn’t returning anything!

The error makes a lot of sense, it’s just that I didn’t pay close attention to the code and went quickly through it.

No, problem! Your suggestion already helped me :wink: