A tuple type element list cannot be empty. 1

A tuple type element list cannot be empty.

// bad
this.sService.getSome().then((value: []) => {
      if (value.length > 0) {
        console.log(value)
      }
});

//fix
this.sService.getSome().then((value: [{}]) => {
      if (value.length > 0) {
        console.log(value)
      }
});

Here is what the above code is Doing:
1. The first line is a promise that returns an array of objects.
2. The second line is a conditional that checks if the array has a length greater than 0.
3. The third line is a console.log of the array.

The problem is that the array is not typed. The compiler doesn’t know what the array contains.

The fix is to type the array as an array of objects.

The compiler will now know that the array contains objects and will allow you to access the properties of those objects.

Similar Posts