Tengo un error como este en mi proyecto:
Rechazo no controlado (TypeError): intento no válido de difundir una instancia no iterable. Para ser iterables, los objetos que no son de matriz deben tener un método Symbol.iterator
Aquí está mi código SortContracts.ts:
function sortContracts( contracts: ContractUsage[], sortField?: SortType, sortDirection?: SortDirection ): any[] { let sortFunction:any switch (sortField) { // Sort by End Date case SortType.DATE_SORT: if (sortDirection === SortDirection.ASC) { // Sort by End Date ASC sortFunction = (a:any, b:any) => endDateSortAscFunc(a, b); } else { // Sort by End Date DESC sortFunction = (a:any, b:any) => endDateSortDescFunc(a, b); } break; // Sort by ContractID case SortType.CONTRACT_SORT: if (sortDirection === SortDirection.ASC) { // Sort by ContractID ASC sortFunction = (a:any, b:any) => contractIdSortAscFunc(a, b); } else { // Sort by ContractID DESC sortFunction = (a:any, b:any) => contractIdSortDescFunc(a, b); } break; case SortType.USAGE_ORDER: if (sortDirection === SortDirection.ASC) { sortFunction = (a:any, b:any) => usageOrderSortAscFunc(a, b); } else { sortFunction = (a:any, b:any) => usageOrderSortDescFunc(a, b); } break; // default sort default: sortFunction = (a:any, b:any) => contractIdSortAscFunc(a, b); } // Return the sorted contracts console.log('contract here: ', [...contracts].sort(sortFunction)) return [...contracts].sort(sortFunction); }La variable que está tratando de difundir (es decir, [...contracts] ) no es iterable . Si desea utilizar este operador, debe tener esta variable iterable . Verifique la variable si es realmente una matriz (o cualquier otro tipo iterable) y si no es nula o indefinida .