You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
Can you use generic types instead converting the whole data object to type any. Otherwise all TypeScript information about the object properties will be lost!
Here is my implementation:
/** * Search Filter Pipe * @param items object from array * @param term term's search * @param excludes array of strings which will ignored during search */publictransform<T>(items: T[],term: string,excludes: any[]=[]): T[]{if(!term||!items)returnitems;returnSearchFilterPipe.filter(items,term,excludes);}/** * Filer items[] * @param items List of items to filter * @param term a string term to compare with every property of the list * @param excludes List of keys which will be ignored during search */privatestaticfilter<T>(items: T[],term: string,excludes: any[]): T[]{consttoCompare=term.toLowerCase();/** * Check filterable object props */functioncheckInside(item: any,term: string): boolean{if(typeofitem==='string'&&item.toString().toLowerCase().includes(toCompare)){returntrue;}for(letpropertyinitem){if(item[property]===null||item[property]==undefined||excludes.includes(property)){continue;}if(typeofitem[property]==='object'){if(checkInside(item[property],term)){returntrue;}}elseif(item[property].toString().toLowerCase().includes(toCompare)){returntrue;}}returnfalse;}returnitems.filter(function(item){returncheckInside(item,term);});}
The text was updated successfully, but these errors were encountered:
Can you use generic types instead converting the whole data object to type
any
. Otherwise all TypeScript information about the object properties will be lost!Here is my implementation:
The text was updated successfully, but these errors were encountered: