-1

I'm trying to get unique value using key from array of object. Everything seems good but function call inside reduce getting Uncaught (in promise): TypeError: Cannot read property 'getFile' of undefined. Is there any possile way to call function inside reduce in TypeScript.

_.reduce(items, function(result, value, key) {
    let file = this.getFile(value);
    (result[value] || (result[value] = [])).push(key);
    return result;
}, {});

The function which i'm calling inside reduce.

async getFile(fileEntry) {
        try {
            return await new Promise((resolve, reject) =>
            fileEntry.file(resolve, reject)
            );
        } catch (err) {
            console.log(err);
        }
    }

Thanks in advance.

dhamo dharan
  • 712
  • 1
  • 10
  • 25

1 Answers1

0

From your question it is not clear how you have defined your getFile function.

Is it like this

//example 1
async function getFile(fileEntry){
//function body
}

or like this

//example 2
this.getFile = async function(fileEntry){
//function body
}

If getFile function is defined like the example 1, then you should call it like this

let file = getFile(value);

Hope, this will help you. Thanks!

Adnan Sharif
  • 919
  • 7
  • 17