I am using a remove
method to emit a value to store. But getting an error as
error TS2322: Type 'void' is not assignable to type 'Promise<void> | JQueryPromise<void>'.
- how to fix this?
here the sample what i use:
https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/CRUDOperations/Angular/Light/
here is my ts code :
ngOnChanges() {
if (!this.subsystems) { return; }
this.dataSource = new CustomStore({
key: 'Id',
load: (loadOptions) => this.loadData(loadOptions),
update: (key: number, values) => this.updateData(key, values),
remove: (key) => this.removeData(key) //getting error here
});
}
loadData(loadOptions) {
return new Promise((resolve, reject) => {
this.dataGrid.columns = this.columns;
resolve({ data: this.subsystems, totalCount: 10 });
});
}
removeData(key: any) {
this.deleteId.emit(key);
}
error TS2322: Type 'void' is not assignable to type 'Promise | JQueryPromise'
Then have the function underlined in red return a promise.
removeData(key: any) {
this.deleteId.emit(key);
return Promise.resolve();
}
That's a quick and somewhat dirty fix, though. Ideally, that promise would be resolved only after whoever listens to this.deleteId
concluded all his business (but if nothing asynchronous happens there, you should be fine).