d.ts: Function -> (() => void | string | any, etc)#33163
d.ts: Function -> (() => void | string | any, etc)#33163mpreyskurantov wants to merge 1 commit intoDevExpress:26_1from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refines public TypeScript typings by replacing the overly-broad Function type with an explicit function signature for the keyExpr option across the core .d.ts files and the Angular/Vue wrappers.
Changes:
- Updated
CollectionWidgetOptions.keyExprin core typings (dx.all.d.tsandui.collection_widget.base.d.ts) fromstring | Functionto a specific callback type. - Propagated the new
keyExprtyping into Angular wrapper inputs/outputs for Tabs/List/Accordion. - Propagated the new
keyExprtyping into Vue wrapper prop definitions for Tabs/List/Accordion.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/devextreme/ts/dx.all.d.ts | Updates CollectionWidgetOptions.keyExpr type in the aggregated TS declarations. |
| packages/devextreme/js/ui/collection/ui.collection_widget.base.d.ts | Updates the source CollectionWidgetOptions.keyExpr type used by many widgets. |
| packages/devextreme-vue/src/tabs.ts | Updates Vue Tabs keyExpr prop type to match new declarations. |
| packages/devextreme-vue/src/list.ts | Updates Vue List keyExpr prop type to match new declarations. |
| packages/devextreme-vue/src/accordion.ts | Updates Vue Accordion keyExpr prop type to match new declarations. |
| packages/devextreme-angular/src/ui/tabs/index.ts | Updates Angular Tabs @Input()/@Output() typings for keyExpr. |
| packages/devextreme-angular/src/ui/list/index.ts | Updates Angular List @Input()/@Output() typings for keyExpr. |
| packages/devextreme-angular/src/ui/accordion/index.ts | Updates Angular Accordion @Input()/@Output() typings for keyExpr. |
| @Input() | ||
| get keyExpr(): Function | string { | ||
| get keyExpr(): (() => string) | string { | ||
| return this._getOption('keyExpr'); | ||
| } | ||
| set keyExpr(value: Function | string) { | ||
| set keyExpr(value: (() => string) | string) { | ||
| this._setOption('keyExpr', value); |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but for collection widgets this callback is used as a key getter and is invoked with the item data. This typing breaks common Angular usage like (item) => item.id and also forces the key to string.
Suggested fix: type it as ((item: TItem) => TKey) | string (and update the corresponding setter type to match).
|
|
||
| */ | ||
| @Output() keyExprChange: EventEmitter<Function | string>; | ||
| @Output() keyExprChange: EventEmitter<(() => string) | string>; |
There was a problem hiding this comment.
keyExprChange is now EventEmitter<(() => string) | string>, but it should stay aligned with the keyExpr option type (a key getter invoked with item data and returning the key type). Otherwise the wrapper exposes an incorrect/breaking type.
Suggested fix: update to EventEmitter<((item: TItem) => TKey) | string> (or whatever final keyExpr type is chosen).
| @Output() keyExprChange: EventEmitter<(() => string) | string>; | |
| @Output() keyExprChange: EventEmitter<((item: any) => any) | string>; |
| @Input() | ||
| get keyExpr(): Function | string { | ||
| get keyExpr(): (() => string) | string { | ||
| return this._getOption('keyExpr'); | ||
| } | ||
| set keyExpr(value: Function | string) { | ||
| set keyExpr(value: (() => string) | string) { | ||
| this._setOption('keyExpr', value); |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but this option is used as a key getter and is invoked with the item data. This typing breaks standard usage like (item) => item.id and also narrows keys to string.
Suggested fix: use ((item: TItem) => TKey) | string for both getter and setter.
|
|
||
| */ | ||
| @Output() keyExprChange: EventEmitter<Function | string>; | ||
| @Output() keyExprChange: EventEmitter<(() => string) | string>; |
There was a problem hiding this comment.
keyExprChange is now EventEmitter<(() => string) | string>, which does not match how keyExpr is used (key getter invoked with item data). This is a breaking/inaccurate type for consumers.
Suggested fix: align it with the corrected keyExpr type, e.g. EventEmitter<((item: TItem) => TKey) | string>.
| @Output() keyExprChange: EventEmitter<(() => string) | string>; | |
| @Output() keyExprChange: EventEmitter<((item: any) => any) | string>; |
| @Input() | ||
| get keyExpr(): Function | string { | ||
| get keyExpr(): (() => string) | string { | ||
| return this._getOption('keyExpr'); | ||
| } | ||
| set keyExpr(value: Function | string) { | ||
| set keyExpr(value: (() => string) | string) { | ||
| this._setOption('keyExpr', value); |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but in collection widgets this callback is treated as a key getter and invoked with item data. The zero-arg signature and forced string return type are both incompatible with common usage.
Suggested fix: type it as ((item: TItem) => TKey) | string for both getter and setter.
|
|
||
| */ | ||
| @Output() keyExprChange: EventEmitter<Function | string>; | ||
| @Output() keyExprChange: EventEmitter<(() => string) | string>; |
There was a problem hiding this comment.
keyExprChange is now EventEmitter<(() => string) | string>, which doesn’t reflect actual keyExpr semantics (function should accept item data and return the key type). This will surface an incorrect public API in the Angular wrapper.
Suggested fix: align to EventEmitter<((item: TItem) => TKey) | string> (or whatever the final keyExpr type is).
| @Output() keyExprChange: EventEmitter<(() => string) | string>; | |
| @Output() keyExprChange: EventEmitter<((item: any) => string) | string>; |
| items: Array as PropType<Array<any | dxTabsItem | string>>, | ||
| itemTemplate: {}, | ||
| keyExpr: [Function, String] as PropType<((() => void)) | string>, | ||
| keyExpr: [Function, String] as PropType<((() => string)) | string>, |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but this option is used as a key getter and is invoked with the item data. The zero-argument function type is incorrect and will reject common usage like (item) => item.id.
Suggested fix: use a signature that accepts item data, e.g. ((item: any) => any) | string (or reuse the exact Properties["keyExpr"] type if available).
| keyExpr: [Function, String] as PropType<((() => string)) | string>, | |
| keyExpr: [Function, String] as PropType<Properties["keyExpr"]>, |
| items: Array as PropType<Array<any | dxListItem | string>>, | ||
| itemTemplate: {}, | ||
| keyExpr: [Function, String] as PropType<((() => void)) | string>, | ||
| keyExpr: [Function, String] as PropType<((() => string)) | string>, |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but it is used as a key getter called with the item data. The zero-arg callback type is incompatible with typical usage (item) => item.id.
Suggested fix: change to ((item: any) => any) | string (or use the component Properties["keyExpr"] type) to match runtime behavior.
| keyExpr: [Function, String] as PropType<((() => string)) | string>, | |
| keyExpr: [Function, String] as PropType<Properties["keyExpr"]>, |
| itemTemplate: {}, | ||
| itemTitleTemplate: {}, | ||
| keyExpr: [Function, String] as PropType<((() => void)) | string>, | ||
| keyExpr: [Function, String] as PropType<((() => string)) | string>, |
There was a problem hiding this comment.
keyExpr is typed as (() => string) | string, but this option is treated as a key getter invoked with item data. A zero-argument function type will incorrectly reject standard patterns like (item) => item.id.
Suggested fix: type as ((item: any) => any) | string (or reuse the widget Properties["keyExpr"] type) to reflect actual usage.
| keyExpr: [Function, String] as PropType<((() => string)) | string>, | |
| keyExpr: [Function, String] as PropType<Properties["keyExpr"]>, |
No description provided.