filter is not a function

I have a function that filters a parameter and when I view the function output, it says subCategories.filter is not a function, how can I fix this?

export function countProducts ( locationId , mainCategory , subCategories ) {
const productQuery = wixData . query ( ‘ItemLocation’ )
. eq ( ‘isActive’ , true )
. eq ( ‘location’ , locationId );
console . log ( 'countProducts: ’ , productQuery );

**if**  ( mainCategory  &&  subCategories ) { 
    **return**  productQuery . hasSome ( 'collectionIds' ,  subCategories . filter (( sub ) => ( mainCategory  !==  sub ))). count (); 
}  **else if**  ( mainCategory  && ! subCategories ) { 
    **return**  wixData . query ( 'LocationCategory' ). eq ( 'location' ,  locationId ). eq ( 'title' ,  mainCategory ). find () 
        . then (({  items  }) => { 
            **if**  ( items . length  ===  0 ) { 
                **return**  {  items : [] }; 
            } 

            **const**  catIds  =  items [ 0 ]. categories . map (({  _id  }) => ( _id )); 
            **return**  productQuery . hasSome ( 'collectionIds' ,  catIds ). count (); 
        }); 
}  **else**  { 
    **return**  wixData . query ( 'CategoriesLocation' ). eq ( 'location' ,  locationId ). find () 
        . then (({  items  }) => { 
            **if**  ( items . length  ===  0 ) { 
                **return**  {  items : [] }; 
            } 

            **const**  catIds  = []; 
            items . forEach (({  categories  }) => { 
                categories . forEach (({  _id  }) => { 
                    **if**  (! catIds . includes ( _id )) { 
                        catIds . push ( _id ); 
                    } 
                }); 
            }); 
            **return**  productQuery . hasSome ( 'collectionIds' ,  catIds ). count (); 
        }); 
} 

}

Filter is not a valid function for a wixData query. See WixDataQuery - Velo API Reference - Wix.com