Skip to content

Commit 2f3ed8b

Browse files
fix: address the scenario when extrenal type parameter is passed to DeepPartial (T1263537) (DevExpress#29044)
1 parent 32d65f5 commit 2f3ed8b

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

e2e/compilation-cases/T1263537.ts

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

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
@@ -4850,11 +4850,13 @@ declare module DevExpress.core {
48504850
/**
48514851
* @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.
48524852
*/
4853-
export type DeepPartial<T> = T extends Scalar
4854-
? T
4855-
: {
4856-
[P in keyof T]?: DeepPartial<T[P]>;
4857-
};
4853+
export type DeepPartial<T> =
4854+
| T
4855+
| (T extends Scalar
4856+
? T
4857+
: {
4858+
[P in keyof T]?: DeepPartial<T[P]>;
4859+
});
48584860
/**
48594861
* [descr:DefaultOptionsRule]
48604862
*/

0 commit comments

Comments
 (0)