-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address the scenario when extrenal type parameter is passed to DeepPa…
…rtial cond type
- Loading branch information
1 parent
dbecbe0
commit d8e4b81
Showing
16 changed files
with
128 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
ODataStore, CustomStore, Store, LoadOptions, | ||
} from 'devextreme/common/data'; | ||
|
||
import { DeepPartial } from 'devextreme/common'; | ||
|
||
// Remove the 'ts-expect-error' below to see the current issue: | ||
// Entity is not compatible with DeepPartial<Entity> | ||
function initCustomStore<Entity, Id>(oDataStore: ODataStore<Entity, Id>): Store<Entity, Id> { | ||
const customStore = new CustomStore<Entity, Id>({ | ||
key: 'id', | ||
byKey: (key: Id) => oDataStore.byKey(key), | ||
insert: (e: Entity) => oDataStore.insert(e), | ||
load: (options: LoadOptions<Entity>) => oDataStore.load(options), | ||
remove: (key: Id) => oDataStore.remove(key), | ||
totalCount: (obj) => oDataStore.totalCount(obj), | ||
// @ts-expect-error - The initial issue | ||
update: (key: Id, updated: Entity) => oDataStore.update(key, updated), | ||
}); | ||
return customStore; | ||
} | ||
|
||
// If this TS issue is fixed: https://github.com/microsoft/TypeScript/issues/23132 | ||
// there will be a good workaround to use type constraints to make such an assignment possible | ||
function initCustomStore3<Entity extends object, Id>( | ||
oDataStore: ODataStore<Entity, Id>, | ||
): Store<Entity, Id> { | ||
const customStore = new CustomStore<Entity, Id>({ | ||
key: 'id', | ||
byKey: (key: Id) => oDataStore.byKey(key), | ||
insert: (e: Entity) => oDataStore.insert(e), | ||
load: (options: LoadOptions<Entity>) => oDataStore.load(options), | ||
remove: (key: Id) => oDataStore.remove(key), | ||
totalCount: (obj) => oDataStore.totalCount(obj), | ||
// @ts-expect-error - How it will hopefully work in TypeScript 5.8.0+ | ||
update: (key: Id, updated: Entity) => oDataStore.update(key, updated), | ||
}); | ||
return customStore; | ||
} | ||
|
||
// Currenlty, we can only publish DeepPartial, which will be a black box | ||
// equal to only itself when initialized with a type parameter. | ||
// Users will be able to make DeepPartial<ExternalTypeParameter> type to avoid the TS error. | ||
function initCustomStore4<Entity, Id>(oDataStore: ODataStore<Entity, Id>): Store<Entity, Id> { | ||
const customStore = new CustomStore<Entity, Id>({ | ||
key: 'id', | ||
byKey: (key: Id) => oDataStore.byKey(key), | ||
insert: (e: Entity) => oDataStore.insert(e), | ||
load: (options: LoadOptions<Entity>) => oDataStore.load(options), | ||
remove: (key: Id) => oDataStore.remove(key), | ||
totalCount: (obj) => oDataStore.totalCount(obj), | ||
update: (key: Id, updated: DeepPartial<Entity>) => oDataStore.update(key, updated), | ||
}); | ||
return customStore; | ||
} | ||
|
||
// Proof that it currently works if we are dealing with resolved types, not type parameters | ||
type Key = number; | ||
type Data = object; | ||
|
||
function initCustomStore2(oDataStore: ODataStore<Data, Key>): Store<Data, Key> { | ||
const customStore = new CustomStore<Data, Key>({ | ||
key: 'id', | ||
byKey: (key: Key) => oDataStore.byKey(key), | ||
insert: (e: Data) => oDataStore.insert(e), | ||
load: (options: LoadOptions<Data>) => oDataStore.load(options), | ||
remove: (key: Key) => oDataStore.remove(key), | ||
totalCount: (obj) => oDataStore.totalCount(obj), | ||
update: (key: Key, updated: Data) => oDataStore.update(key, updated), | ||
}); | ||
return customStore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type Scalar = undefined | null | string | String | number | Number | bigint | BigInteger | boolean | Boolean | Date | Function | Symbol | Array<unknown>; | ||
|
||
export type OmitInternal<T> = Omit<T, `${'_' | '$'}${any}`>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.