Start a new topic

Kinvey Studio

Hi I am writing some custom code to sort a collection. The code works and displays correctly in my app, however, the following error is being generated: [19-08-29 20:31:47.384] (CLI) ERROR in src/app/modules/settings/categories-list-mobile/categories-list-mobile.component.tns.ts(45,30): error TS2339: Property 'sort' does not exist on type 'AggregationState | EntityState | CollectionState'. Property 'sort' does not exist on type 'AggregationState'. My working code is: import { Inject, Injector } from '@angular/core'; import { CategoriesListMobileViewBaseComponent } from '@src/app/modules/settings/categories-list-mobile/categories-list-mobile.base.component'; import { DataServiceConfig } from '@src/app/core/data/interfaces/data-service-config.interface'; import { CollectionState } from '../../../core/data/data-state.service'; import { InitDataServiceOptions } from '@src/app/core/data/helpers/data-service-utils'; export class CategoriesListMobileViewComponent extends CategoriesListMobileViewBaseComponent { public categoryServiceConfig: DataServiceConfig; public categoryServiceOptions: InitDataServiceOptions; public categoryInitialState: CollectionState; constructor(@Inject(Injector) injector: Injector) { super(injector); } protected initData(config: { [key: string]: DataServiceConfig }) { const categoryServiceConfig = super.initData(super.getDataConfig()); const categoryOptions = categoryServiceConfig.dataServices.categories; const categoryInitialState = categoryOptions.initialState; categoryInitialState.sort = [{ field: 'sortOrder' }]; console.log(categoryInitialState); return categoryServiceConfig; } }
1 Comment

Sorry for above post - not sure why my post lost all it's formatting of the code.


Anyway - I have solved the issue of the error message : 


Property 'sort' does not exist on type 'AggregationState | EntityState | CollectionState'. Property 'sort' does not exist on type 'AggregationState'.


If I don't assign a type to the variable that points to the object that is of type , then this error appears, even though the collection being retrieved from Kinvey is a multi-entity collection, however if I declare it explicitly, then the error dissappears.  In either situation the sort order is applied!


eg  This returns the error:  const categoryInitialState = categoryServiceOptions.initialState;

 


However, assigning the type explicitly prevents the error message


 

const categoryInitialState: CollectionState = categoryServiceOptions.initialState;

 


So, hope this helps someone else at some stage!




Login or Signup to post a comment