diff --git a/e2e/compilation-cases/T1316896.ts b/e2e/compilation-cases/T1316896.ts new file mode 100644 index 000000000000..448bf328d4cc --- /dev/null +++ b/e2e/compilation-cases/T1316896.ts @@ -0,0 +1,54 @@ +import { ArrayStore } from 'devextreme/common/data'; + +interface Entity { + id?: string; + name?: string; +} + +type Change = { + type: 'insert' | 'update' | 'remove'; + data?: TItem; + key?: TKey; + index?: number; +}; + +function notify(changes: Array>): void { + const change = changes[0]; + if (change?.data?.id && change.key) { + const identifier: string = change.key; + const newId: string = change.data.id; + + const ensureString: string = `${identifier}:${newId}`; + // eslint-disable-next-line no-console + // console.log(ensureString); + } +} + +const store = new ArrayStore({ + key: 'id', + data: [{ id: '1', name: 'Initial' }], + onPush: notify, +}); + +function load(items: Entity[]): void { + const changes: Array> = items.map((data): Change => ({ + key: data.id, + data, + type: 'insert', + })); + + store.push(changes); +} + +function pushSingle(): void { + store.push([ + { + key: '2', + data: { id: '2', name: 'New entity' }, + type: 'insert', + }, + ]); +} + +load([{ id: '3', name: 'Batch load' }]); +pushSingle(); diff --git a/packages/devextreme/js/data/store.d.ts b/packages/devextreme/js/data/store.d.ts index 69688449b727..ee385c7b3ecc 100644 --- a/packages/devextreme/js/data/store.d.ts +++ b/packages/devextreme/js/data/store.d.ts @@ -2,6 +2,13 @@ import { DxPromise, DxExtendedPromise } from '../core/utils/deferred'; import { DeepPartial } from '../core'; import { FilterDescriptor, GroupDescriptor, LoadOptions } from '../common/data'; +type StoreChange = { + type: 'insert' | 'update' | 'remove'; + data?: DeepPartial; + key?: TKey; + index?: number; +}; + /** * @docid StoreOptions * @namespace DevExpress.common.data @@ -57,10 +64,11 @@ export type StoreOptions< onModifying?: Function; /** * @docid StoreOptions.onPush + * @type_function_param1 changes:Array * @action * @public */ - onPush?: ((changes: Array) => void); + onPush?: ((changes: Array>) => void); /** * @docid StoreOptions.onRemoved * @type_function_param1 key:object|string|number @@ -166,7 +174,7 @@ export class Store< * @param1 changes:Array * @public */ - push(changes: Array<{ type: 'insert' | 'update' | 'remove'; data?: DeepPartial; key?: TKey; index?: number }>): void; + push(changes: Array>): void; /** * @docid * @publicName remove(key) diff --git a/packages/devextreme/ts/dx.all.d.ts b/packages/devextreme/ts/dx.all.d.ts index a42643d2366b..3fbb54db3093 100644 --- a/packages/devextreme/ts/dx.all.d.ts +++ b/packages/devextreme/ts/dx.all.d.ts @@ -4094,14 +4094,7 @@ declare module DevExpress.common.data { /** * [descr:Store.push(changes)] */ - push( - changes: Array<{ - type: 'insert' | 'update' | 'remove'; - data?: DevExpress.core.DeepPartial; - key?: TKey; - index?: number; - }> - ): void; + push(changes: Array>): void; /** * [descr:Store.remove(key)] */ @@ -4157,7 +4150,7 @@ declare module DevExpress.common.data { /** * [descr:StoreOptions.onPush] */ - onPush?: (changes: Array) => void; + onPush?: (changes: Array>) => void; /** * [descr:StoreOptions.onRemoved] */ @@ -7858,6 +7851,15 @@ declare module DevExpress.data { * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */ export type SortDescriptor = KeySelector | OrderingDescriptor; + /** + * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. + */ + type StoreChange = { + type: 'insert' | 'update' | 'remove'; + data?: DevExpress.core.DeepPartial; + key?: TKey; + index?: number; + }; /** * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */