Skip to content

Commit d621d31

Browse files
fix: address the scenario when extrenal type parameter is passed to DeepPa… (DevExpress#28729)
1 parent 9209c05 commit d621d31

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

e2e/compilation-cases/T1263537.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
ODataStore, CustomStore, Store, LoadOptions,
3+
} from 'devextreme/common/data';
4+
5+
// Remove the 'ts-expect-error' below to see the current issue:
6+
// Entity is not compatible with DeepPartial<Entity>
7+
function initCustomStore<Entity, Id>(oDataStore: ODataStore<Entity, Id>): Store<Entity, Id> {
8+
const customStore = new CustomStore<Entity, Id>({
9+
key: 'id',
10+
byKey: (key: Id) => oDataStore.byKey(key),
11+
insert: (e: Entity) => oDataStore.insert(e),
12+
load: (options: LoadOptions<Entity>) => oDataStore.load(options),
13+
remove: (key: Id) => oDataStore.remove(key),
14+
totalCount: (obj) => oDataStore.totalCount(obj),
15+
update: (key: Id, updated: Entity) => oDataStore.update(key, updated),
16+
});
17+
return customStore;
18+
}
19+
20+
// If this TS issue is fixed: https://github.com/microsoft/TypeScript/issues/23132
21+
// there will be a good workaround to use type constraints to make such an assignment possible
22+
function initCustomStore3<Entity extends object, Id>(
23+
oDataStore: ODataStore<Entity, Id>,
24+
): Store<Entity, Id> {
25+
const customStore = new CustomStore<Entity, Id>({
26+
key: 'id',
27+
byKey: (key: Id) => oDataStore.byKey(key),
28+
insert: (e: Entity) => oDataStore.insert(e),
29+
load: (options: LoadOptions<Entity>) => oDataStore.load(options),
30+
remove: (key: Id) => oDataStore.remove(key),
31+
totalCount: (obj) => oDataStore.totalCount(obj),
32+
update: (key: Id, updated: Entity) => oDataStore.update(key, updated),
33+
});
34+
return customStore;
35+
}

packages/devextreme/js/core/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export type Xor<T1, T2 = never, T3 = never, T4 = never, T5 = never, T6 = never,
2020
| Seal<T9, KeysOf<T1, T2, T3, T4, T5, T6, T7, T8>>;
2121

2222
export type Scalar = undefined | null | string | String | number | Number | bigint | BigInteger | boolean | Boolean | Date | Function | Symbol | Array<unknown>;
23-
export type DeepPartial<T> = T extends Scalar ? T : {
23+
export type DeepPartial<T> = T | (T extends Scalar ? T : {
2424
[P in keyof T]?: DeepPartial<T[P]>;
25-
};
25+
});
2626

2727
type ItemType<T> = T extends (infer TItem)[] ? TItem : T;
2828
type Property<T, TPropName extends string> = T extends Partial<Record<TPropName, infer TValue>> ? TValue : never;

packages/devextreme/ts/dx.all.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6521,11 +6521,13 @@ declare module DevExpress.core {
65216521
/**
65226522
* @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.
65236523
*/
6524-
export type DeepPartial<T> = T extends Scalar
6525-
? T
6526-
: {
6527-
[P in keyof T]?: DeepPartial<T[P]>;
6528-
};
6524+
export type DeepPartial<T> =
6525+
| T
6526+
| (T extends Scalar
6527+
? T
6528+
: {
6529+
[P in keyof T]?: DeepPartial<T[P]>;
6530+
});
65296531
/**
65306532
* [descr:DevicesObject]
65316533
*/

0 commit comments

Comments
 (0)