@@ -14,7 +14,7 @@ import {
1414 when ,
1515} from '@js/core/utils/deferred' ;
1616import { each } from '@js/core/utils/iterator' ;
17- import { isDefined } from '@js/core/utils/type' ;
17+ import { isDefined , isObject } from '@js/core/utils/type' ;
1818import type { DxEvent } from '@js/events' ;
1919import type { ItemLike , SelectionChangeInfo } from '@js/ui/collection/ui.collection_widget.base' ;
2020import errors from '@js/ui/widget/ui.errors' ;
@@ -76,7 +76,8 @@ class CollectionWidget<
7676> extends BaseCollectionWidget < TProperties , TItem , TKey > {
7777 static _userOptions = { } ;
7878
79- _selection ! : Selection ;
79+ // @ts -expect-error TItem
80+ _selection ! : Selection < TItem , TKey , false > ;
8081
8182 _editStrategy ! : PlainEditStrategy < TItem , TKey > ;
8283
@@ -169,7 +170,7 @@ class CollectionWidget<
169170 return this . _editStrategy . getItemsByKeys ( selectedItemKeys , selectedItems ) ;
170171 }
171172
172- _getKeyByIndex ( index : CollectionItemIndex ) : unknown {
173+ _getKeyByIndex ( index : CollectionItemIndex ) : TKey {
173174 return this . _editStrategy . getKeyByIndex ( index ) ;
174175 }
175176
@@ -224,7 +225,8 @@ class CollectionWidget<
224225 const { itemsGetter } = this . _editStrategy ;
225226 const { selectionMode, maxFilterLengthInRequest } = this . option ( ) ;
226227
227- this . _selection = new Selection ( {
228+ // @ts -expect-error TItem
229+ this . _selection = new Selection < TItem , TKey , false > ( {
228230 allowNullValue : this . _nullValueSelectionSupported ( ) ,
229231 mode : selectionMode ,
230232 maxFilterLengthInRequest,
@@ -259,7 +261,7 @@ class CollectionWidget<
259261 } ,
260262 key : this . key . bind ( this ) ,
261263 keyOf : this . keyOf . bind ( this ) ,
262- load ( options ) : DeferredObj < unknown > {
264+ load ( options ) : DeferredObj < TItem [ ] > {
263265 const dataController = that . _dataController ;
264266 options . customQueryParams = dataController . loadOptions ( ) ?. customQueryParams ;
265267 options . userData = dataController . userData ( ) ;
@@ -276,7 +278,7 @@ class CollectionWidget<
276278 dataController . applyMapFunction ( items ) ;
277279 } ) ;
278280 }
279- return Deferred ( ) . resolve ( this . plainItems ( ) ) ;
281+ return Deferred < TItem [ ] > ( ) . resolve ( this . plainItems ( ) ) ;
280282 } ,
281283 // eslint-disable-next-line @stylistic/max-len
282284 // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/explicit-function-return-type
@@ -479,7 +481,8 @@ class CollectionWidget<
479481
480482 const { grouped } = this . option ( ) ;
481483
482- if ( grouped && normalizedSelection ?. items ) {
484+ const hasSubItems = ( item : TItem ) : item is TItem & { items : TItem [ ] } => isObject ( item ) && 'items' in item && Array . isArray ( item . items ) ;
485+ if ( grouped && hasSubItems ( normalizedSelection ) ) {
483486 normalizedSelection . items = [ normalizedSelection . items [ 0 ] ] ;
484487 }
485488
0 commit comments