From 0a558db744d1dc2b143439bde3ad91689f7aca78 Mon Sep 17 00:00:00 2001 From: Eldar Iusupzhanov Date: Wed, 18 Nov 2026 17:58:50 +0800 Subject: [PATCH 1/2] fix --- .../options_controller_base.test.ts | 23 ++++--- .../options_controller_base.ts | 64 +++++++++---------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.test.ts b/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.test.ts index be569b4cacc5..a9f14185c446 100644 --- a/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.test.ts +++ b/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.test.ts @@ -1,16 +1,20 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { beforeEach, describe, expect, it, jest, } from '@jest/globals'; +import type { Component } from '@js/core/component'; import { createComponentMock } from './component.mock'; import { OptionsController } from './options_controller_base'; -const setup = >( +const setup = ( options: TOptions, defaultOptions: TOptions, -) => { +): { + component: Component; + optionsController: OptionsController; + onOptionChangedMock: jest.Mock; +} => { const onOptionChangedMock = jest.fn(); const component = createComponentMock(options, defaultOptions); @@ -90,6 +94,7 @@ describe('oneWay', () => { const mixedComplexOptions: MixedOptions = { value: { valueA: 'A', valueB: 'B' }, }; + const mixedComplexValue = mixedComplexOptions.value as { valueA?: string; valueB?: string }; describe('initial values', () => { describe('plain options', () => { @@ -133,7 +138,7 @@ describe('oneWay', () => { const value = optionsController.oneWay('nested.value'); - expect(value.peek()).toBe(nestedPlainOptions.nested!.value); + expect(value.peek()).toBe(nestedPlainOptions.nested?.value); }); it('should have initial default value if parent config option is undefined', () => { @@ -277,7 +282,7 @@ describe('oneWay', () => { }); it('should have initial value same as passed in config if default not specified', () => { - const optionalOptions = { optionalValue: function optionalFnValue() {} }; + const optionalOptions = { optionalValue: function optionalFnValue(): void {} }; const { optionsController } = setup( optionalOptions, defaultFunctionOptions, @@ -306,7 +311,7 @@ describe('oneWay', () => { const value = optionsController.oneWay('value.valueA'); - expect(value.peek()).toStrictEqual((mixedComplexOptions.value as any).valueA); + expect(value.peek()).toStrictEqual(mixedComplexValue.valueA); }); it('should have initial value undefined if parent is plain value', () => { @@ -322,7 +327,7 @@ describe('oneWay', () => { const value = optionsController.oneWay('value.valueA'); - expect(value.peek()).toBe((mixedComplexOptions.value as any).valueA); + expect(value.peek()).toBe(mixedComplexValue.valueA); }); }); @@ -600,7 +605,7 @@ describe('oneWay', () => { const value = optionsController.oneWay('value.valueA'); component.option('value.valueA', undefined); - expect(value.peek()).toBe((mixedComplexOptions.value as any)?.valueA); + expect(value.peek()).toBe(mixedComplexValue.valueA); }); it('should update to undefined if parent option update to plain one', () => { @@ -624,7 +629,7 @@ describe('oneWay', () => { const value = optionsController.oneWay('value.valueA'); component.option('value', undefined); - expect(value.peek()).toBe((mixedComplexOptions.value as any)?.valueA); + expect(value.peek()).toBe(mixedComplexValue.valueA); }); it('should update to undefined if default value is plain', () => { diff --git a/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.ts b/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.ts index b6c4389a37a2..eaa4d07e994e 100644 --- a/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.ts +++ b/packages/devextreme/js/__internal/grids/new/grid_core/options_controller/options_controller_base.ts @@ -1,6 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ - import { Component } from '@js/core/component'; import { getPathParts } from '@js/core/utils/data'; import type { ChangedOptionInfo } from '@js/events'; @@ -20,9 +17,9 @@ import type { TemplateProperty, } from './types'; -function getOr(cache: Record, key: string, orElse: () => T): T { +function getOr(cache: Record, key: string, orElse: () => T): T { if (cache[key]) { - return cache[key]; + return cache[key] as T; } const value = orElse(); @@ -32,10 +29,13 @@ function getOr(cache: Record, key: string, orElse: () => T): T { } export class OptionsController< - TProps extends Record, + TProps extends object, TDefaultProps extends TProps = TProps, > { - private readonly cache = { + private readonly cache: Record< + 'oneWay' | 'oneWayWithChanges' | 'twoWay' | 'action' | 'template', + Record + > = { oneWay: {}, oneWayWithChanges: {}, twoWay: {}, @@ -115,7 +115,7 @@ export class OptionsController< () => getTreeNodeByPath( this.internalOptions.value.options, pathArray, - ), + ) as PropertyWithDefaults, ); }); } @@ -131,7 +131,10 @@ export class OptionsController< const { options, changes } = this.internalOptions.value; return { - value: getTreeNodeByPath(options, pathArray), + value: getTreeNodeByPath( + options, + pathArray, + ) as PropertyWithDefaults, changes, }; }, @@ -142,21 +145,24 @@ export class OptionsController< public twoWay( name: TProp, ): Signal> { - return getOr(this.cache.twoWay, name, () => { + type TValue = PropertyWithDefaults; + + return getOr(this.cache.twoWay, name, (): Signal => { // eslint-disable-next-line @typescript-eslint/no-this-alias const that = this; - const obs = signal(this.component.option(name)); + const obs = signal(this.component.option(name) as TValue); effect(() => { - obs.value = this.oneWay(name).value as any; + obs.value = this.oneWay(name).value; }); return { - get value(): any { + get value(): TValue { return obs.value; }, - set value(value: any) { + set value(value: TValue) { const isInitialized = that.initialized.peek(); const callbackName = `on${name}Change`; - const callback = that.component.option(callbackName) as any; + const callback = that.component.option(callbackName) as + ((value: TValue) => void) | undefined; const isControlled = that.isControlledMode && that.component.option(name) !== undefined; if (isControlled) { @@ -164,6 +170,7 @@ export class OptionsController< return; } + // @ts-expect-error Component.option() doesn't resolve nested option paths that.component.option(name, value); // 🚨🚨🚨 Hotfix for filterSync @@ -177,21 +184,12 @@ export class OptionsController< callback?.(value); }, - peek(): any { + peek(): TValue { return obs.peek(); }, - subscribe(...params: any): any { - // @ts-expect-error - return obs.subscribe(...params); - }, - toJSON(...params: any[]): any { - // @ts-expect-error - return obs.toJSON(...params); - }, - valueOf(...params: any[]): any { - // @ts-expect-error - return obs.valueOf(...params); - }, + subscribe: obs.subscribe.bind(obs), + toJSON: obs.toJSON.bind(obs), + valueOf: obs.valueOf.bind(obs), brand: obs.brand, }; }); @@ -199,7 +197,7 @@ export class OptionsController< public normalizeTemplate(template: Template): ComponentType { // @ts-expect-error - return TemplateWrapper(this.component._getTemplate(template)) as any; + return TemplateWrapper(this.component._getTemplate(template)) as ComponentType; } public template( @@ -208,8 +206,10 @@ export class OptionsController< return getOr(this.cache.template, name, () => { const templateOption = this.oneWay(name); return computed( - // @ts-expect-error - () => templateOption.value && this.normalizeTemplate(templateOption.value) as any, + () => ( + templateOption.value + && this.normalizeTemplate(templateOption.value as Template) + ) as TemplateProperty, ); }); } @@ -223,7 +223,7 @@ export class OptionsController< () => { track(actionOption.value); // @ts-expect-error - return this.component._createActionByOption(name) as any; + return this.component._createActionByOption(name) as ActionProperty; }, ); }); From 50b49f432ad9a071111006ac60c3b1c14f3b7681 Mon Sep 17 00:00:00 2001 From: Eldar Iusupzhanov Date: Wed, 18 Nov 2026 19:42:41 +0800 Subject: [PATCH 2/2] fix ts errors --- .../ui/html_editor/__tests__/image_upload_dialog.test.ts | 1 - .../ui/html_editor/__tests__/table_context_menu.test.ts | 1 - .../ui/html_editor/__tests__/table_properties_form.test.ts | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/html_editor/__tests__/image_upload_dialog.test.ts b/packages/devextreme/js/__internal/ui/html_editor/__tests__/image_upload_dialog.test.ts index de9d372bf830..a80ecb95738e 100644 --- a/packages/devextreme/js/__internal/ui/html_editor/__tests__/image_upload_dialog.test.ts +++ b/packages/devextreme/js/__internal/ui/html_editor/__tests__/image_upload_dialog.test.ts @@ -63,7 +63,6 @@ const getFileUploader = (editor: HtmlEditor): FileUploader => FileUploader.getIn const openFileTab = ({ imageUpload, fileTabIndex }: DialogConfig): HtmlEditor => { const $element = $('
').appendTo(document.body); - // @ts-expect-error direct instantiation is not typed const editor: HtmlEditor = new HtmlEditor($element, { value: VALUE, toolbar: { items: ['image'] }, diff --git a/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_context_menu.test.ts b/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_context_menu.test.ts index 225f8b0e01fa..5b86b1ef9726 100644 --- a/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_context_menu.test.ts +++ b/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_context_menu.test.ts @@ -38,7 +38,6 @@ const editors: HtmlEditor[] = []; const createEditor = (options: Properties): HtmlEditor => { const $element = $('
').appendTo(document.body); - // @ts-expect-error direct instantiation is not typed const editor: HtmlEditor = new HtmlEditor($element, { value: TABLE_MARKUP, ...options }); editors.push(editor); diff --git a/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_properties_form.test.ts b/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_properties_form.test.ts index 0cca1c6a544e..61770673f853 100644 --- a/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_properties_form.test.ts +++ b/packages/devextreme/js/__internal/ui/html_editor/__tests__/table_properties_form.test.ts @@ -66,7 +66,6 @@ const editors: HtmlEditor[] = []; const createEditor = ({ options, caretIndex }: EditorState): HtmlEditor => { const $element = $('
').appendTo(document.body); - // @ts-expect-error direct instantiation is not typed const editor: HtmlEditor = new HtmlEditor($element, { tableContextMenu: { enabled: true }, toolbar: {