ravendb/ravendb-nodejs-client

Map/Reduce TypeError: Object has no method 'flat'

amirbrzz1 opened this issue · 3 comments

In the reduce we I want use some extensions like flat, flatMap, or something new in typescript, I get this error :
TypeError: Object has no method 'flat'


this.reduce((result) =>
            result
                .groupBy((c) => c.mobileNumber)
                .aggregate((groupResult) => {
                    return {
                       employerOrganisationDocumentIds: groupResult.values
                            .map((x) => x.employerOrganisationDocumentIds)
                            .flat()
                            .filter((v, i, a) => a.indexOf(v) === i),

image

if I change my code to avoid using the flat then I can create my index


this.reduce((result) =>
            result
                .groupBy((c) => c.mobileNumber)
                .aggregate((groupResult) => {
                    return {
                       employerOrganisationDocumentIds: groupResult.values
                                .map((x) => x.employerOrganisationDocumentIds)
                               .reduce((acc, val, i) => acc.concat(val), []).filter((v, i, a) => a.indexOf(v) === i),

my typescript version is 4.7.4 like the ravendb

You can add a polyfil for that as additional sources, which will provide this, no?

thanks @ayende for your quick response
I can't get ur point, Do you mean I should use something like the blow code instead of using map


        this.reduce((result) =>
            result
                .groupBy((c) => c.mobileNumber)
                .aggregate((groupResult) => {
                    return {
                        ids: groupResult.values.map(c=>c.ids).reduce((acc, val, i) => acc.concat(val), []),

or there is a config that can I import my polyfill file into Ravendb and use map directly, I prefer the second one because sometimes I should write some custom extensions for typescript it would be great if I can use them directly in the reduce

as as sample :


declare global {
    interface Array<T> {
        __flat_deDupe(this : string[][]): string[];
    }
}

Array.prototype.__flat_deDupe = function(this : string[][]) : string[] {
    return Array.prototype.concat([],this).filter((v, i, a) => a.indexOf(v) === i);
}

//and use in reduce like
ids: groupResult.values.map(c=>c.ids).__flat_deDupe()

if there is a way to register custom extensions like __flat_deDupe or even naturals like map, flat, ... , please give me clue or leave a link for more clarification
thanks again