From f64349ed7ba2f84f10c860142f059c78b633ab13 Mon Sep 17 00:00:00 2001 From: "Rochmar Nicolas (DevExpress)" Date: Wed, 31 Jul 2024 09:35:17 +0800 Subject: [PATCH] Replace as any --- .../events/core/m_emitter.feedback.ts | 6 ++++-- .../events/core/m_emitter_registrator.ts | 18 ++++++++++++------ .../__internal/events/core/m_events_engine.ts | 15 ++++++++++----- .../events/core/m_keyboard_processor.ts | 4 ++-- .../js/__internal/events/core/m_wheel.ts | 3 ++- .../events/gesture/m_emitter.gesture.scroll.ts | 3 ++- .../events/gesture/m_emitter.gesture.ts | 16 ++++++++++------ .../__internal/events/gesture/m_swipeable.ts | 4 ++-- .../devextreme/js/__internal/events/m_hold.ts | 3 ++- .../js/__internal/events/m_pointer.ts | 7 ++++--- .../js/__internal/events/m_remove.ts | 3 ++- .../js/__internal/events/pointer/m_mouse.ts | 12 ++++++++---- .../events/pointer/m_mouse_and_touch.ts | 7 ++++--- 13 files changed, 64 insertions(+), 37 deletions(-) diff --git a/packages/devextreme/js/__internal/events/core/m_emitter.feedback.ts b/packages/devextreme/js/__internal/events/core/m_emitter.feedback.ts index f82c54369798..bf19246fa872 100644 --- a/packages/devextreme/js/__internal/events/core/m_emitter.feedback.ts +++ b/packages/devextreme/js/__internal/events/core/m_emitter.feedback.ts @@ -158,7 +158,8 @@ const FeedbackEmitter = Emitter.inherit({ }, }); -(FeedbackEmitter as any).lock = function (deferred) { +// @ts-expect-error +FeedbackEmitter.lock = function (deferred) { const lockInactive = activeFeedback ? activeFeedback.lockInactive() : noop; deferred.done(lockInactive); @@ -172,7 +173,8 @@ registerEmitter({ ], }); -export const { lock } = (FeedbackEmitter as any); +// @ts-expect-error +export const { lock } = FeedbackEmitter; export { ACTIVE_EVENT_NAME as active, INACTIVE_EVENT_NAME as inactive, diff --git a/packages/devextreme/js/__internal/events/core/m_emitter_registrator.ts b/packages/devextreme/js/__internal/events/core/m_emitter_registrator.ts index 03ea945313be..77540f77ce3c 100644 --- a/packages/devextreme/js/__internal/events/core/m_emitter_registrator.ts +++ b/packages/devextreme/js/__internal/events/core/m_emitter_registrator.ts @@ -27,10 +27,14 @@ const EventManager = Class.inherit({ _attachHandlers() { readyCallbacks.add(() => { const document = domAdapter.getDocument(); - (eventsEngine as any).subscribeGlobal(document, addNamespace(pointerEvents.down, MANAGER_EVENT), this._pointerDownHandler.bind(this)); - (eventsEngine as any).subscribeGlobal(document, addNamespace(pointerEvents.move, MANAGER_EVENT), this._pointerMoveHandler.bind(this)); - (eventsEngine as any).subscribeGlobal(document, addNamespace([pointerEvents.up, pointerEvents.cancel].join(' '), MANAGER_EVENT), this._pointerUpHandler.bind(this)); - (eventsEngine as any).subscribeGlobal(document, addNamespace(wheelEventName, MANAGER_EVENT), this._mouseWheelHandler.bind(this)); + // @ts-expect-error + eventsEngine.subscribeGlobal(document, addNamespace(pointerEvents.down, MANAGER_EVENT), this._pointerDownHandler.bind(this)); + // @ts-expect-error + eventsEngine.subscribeGlobal(document, addNamespace(pointerEvents.move, MANAGER_EVENT), this._pointerMoveHandler.bind(this)); + // @ts-expect-error + eventsEngine.subscribeGlobal(document, addNamespace([pointerEvents.up, pointerEvents.cancel].join(' '), MANAGER_EVENT), this._pointerUpHandler.bind(this)); + // @ts-expect-error + eventsEngine.subscribeGlobal(document, addNamespace(wheelEventName, MANAGER_EVENT), this._mouseWheelHandler.bind(this)); }); }, @@ -280,8 +284,10 @@ const registerEmitter = function (emitterConfig) { }); if (disposeEmitter) { - if ((eventManager as any).isActive(element)) { - (eventManager as any).resetEmitter(emitter); + // @ts-expect-error + if (eventManager.isActive(element)) { + // @ts-expect-error + eventManager.resetEmitter(emitter); } emitter && emitter.dispose(); diff --git a/packages/devextreme/js/__internal/events/core/m_events_engine.ts b/packages/devextreme/js/__internal/events/core/m_events_engine.ts index 66f6a4cd8a59..75b3058cd4db 100644 --- a/packages/devextreme/js/__internal/events/core/m_events_engine.ts +++ b/packages/devextreme/js/__internal/events/core/m_events_engine.ts @@ -61,7 +61,8 @@ const EVENT_PROPERTIES = [ ]; function matchesSafe(target, selector) { - return !isWindow(target) && target.nodeName !== '#document' && (domAdapter as any).elementMatches(target, selector); + // @ts-expect-error + return !isWindow(target) && target.nodeName !== '#document' && domAdapter.elementMatches(target, selector); } const elementDataMap = new WeakMap(); let guid = 0; @@ -187,7 +188,8 @@ function detectPassiveEventHandlersSupport() { }, }); - (window as any).addEventListener('test', null, options); + // @ts-expect-error + window.addEventListener('test', null, options); // eslint-disable-next-line no-empty } catch (e) { } @@ -321,7 +323,8 @@ function getHandlersController(element, eventName) { }; } - eventData.removeListener = (domAdapter as any).listen(element, NATIVE_EVENTS_TO_SUBSCRIBE[eventName] || eventName, eventData.nativeHandler, nativeListenerOptions); + // @ts-expect-error + eventData.removeListener = domAdapter.listen(element, NATIVE_EVENTS_TO_SUBSCRIBE[eventName] || eventName, eventData.nativeHandler, nativeListenerOptions); } special.callMethod(eventName, 'add', element, [handleObject]); @@ -552,7 +555,8 @@ function iterate(callback) { iterateEventNames.apply(this, args); } } else { - iterateEventNames.apply(this, arguments as any); + // @ts-expect-error + iterateEventNames.apply(this, arguments); } }; } @@ -606,7 +610,8 @@ function initEvent(EventClass) { initEvent(normalizeEventArguments(function (src, config) { const srcIsEvent = src instanceof eventsEngine.Event - || (hasWindow() && src instanceof (window as any).Event) + // @ts-expect-error + || (hasWindow() && src instanceof window.Event) || (src.view?.Event && src instanceof src.view.Event); if (srcIsEvent) { diff --git a/packages/devextreme/js/__internal/events/core/m_keyboard_processor.ts b/packages/devextreme/js/__internal/events/core/m_keyboard_processor.ts index 774ed33cf7b3..bc3194beeda1 100644 --- a/packages/devextreme/js/__internal/events/core/m_keyboard_processor.ts +++ b/packages/devextreme/js/__internal/events/core/m_keyboard_processor.ts @@ -74,7 +74,7 @@ const KeyboardProcessor = Class.inherit({ this._isComposingJustFinished = !this._isComposing; }, }); - -(KeyboardProcessor as any).createKeyDownOptions = createKeyDownOptions; +// @ts-expect-error +KeyboardProcessor.createKeyDownOptions = createKeyDownOptions; export default KeyboardProcessor; diff --git a/packages/devextreme/js/__internal/events/core/m_wheel.ts b/packages/devextreme/js/__internal/events/core/m_wheel.ts index 60e28f3995c7..f4f94e27f02a 100644 --- a/packages/devextreme/js/__internal/events/core/m_wheel.ts +++ b/packages/devextreme/js/__internal/events/core/m_wheel.ts @@ -28,13 +28,14 @@ const wheel = { fireEvent({ type: EVENT_NAME, originalEvent: e, + // @ts-expect-error delta: this._normalizeDelta(deltaY, deltaMode), deltaX, deltaY, deltaZ, deltaMode, pointerType: 'mouse', - } as any); + }); e.stopPropagation(); }, diff --git a/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.scroll.ts b/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.scroll.ts index 60bdd27b0c76..b8ba6593c113 100644 --- a/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.scroll.ts +++ b/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.scroll.ts @@ -266,7 +266,8 @@ const ScrollEmitter = GestureEmitter.inherit((function () { }, _end(e) { - const endEventDelta = eventDelta(this._prevEventData, eventData(e) as any); + // @ts-expect-error + const endEventDelta = eventDelta(this._prevEventData, eventData(e)); let velocity = { x: 0, y: 0 }; if (!isDxMouseWheelEvent(e) && endEventDelta.time < INERTIA_TIMEOUT) { diff --git a/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.ts b/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.ts index b49e2ddd6367..b74fd5ff811b 100644 --- a/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.ts +++ b/packages/devextreme/js/__internal/events/gesture/m_emitter.gesture.ts @@ -40,8 +40,8 @@ const setGestureCover = callOnce(() => { const $cover = $('
') .addClass(GESTURE_COVER_CLASS) .css('pointerEvents', 'none'); - - (eventsEngine as any).subscribeGlobal($cover, 'dxmousewheel', (e) => { + // @ts-expect-error + eventsEngine.subscribeGlobal($cover, 'dxmousewheel', (e) => { e.preventDefault(); }); @@ -145,7 +145,8 @@ const GestureEmitter = Emitter.inherit({ _directionConfirmed(e) { const touchBoundary = this._getTouchBoundary(e); - const delta = eventDelta(this._startEventData, eventData(e) as any); + // @ts-expect-error + const delta = eventDelta(this._startEventData, eventData(e)); const deltaX = abs(delta.x); const deltaY = abs(delta.y); @@ -170,7 +171,8 @@ const GestureEmitter = Emitter.inherit({ _adjustStartEvent(e) { const touchBoundary = this._getTouchBoundary(e); - const delta = eventDelta(this._startEventData, eventData(e) as any); + // @ts-expect-error + const delta = eventDelta(this._startEventData, eventData(e)); this._startEvent.pageX += sign(delta.x) * touchBoundary; this._startEvent.pageY += sign(delta.y) * touchBoundary; @@ -227,8 +229,10 @@ const GestureEmitter = Emitter.inherit({ _end: noop, }); -(GestureEmitter as any).initialTouchBoundary = TOUCH_BOUNDARY; -(GestureEmitter as any).touchBoundary = function (newBoundary) { +// @ts-expect-error +GestureEmitter.initialTouchBoundary = TOUCH_BOUNDARY; +// @ts-expect-error +GestureEmitter.touchBoundary = function (newBoundary) { if (isDefined(newBoundary)) { TOUCH_BOUNDARY = newBoundary; return; diff --git a/packages/devextreme/js/__internal/events/gesture/m_swipeable.ts b/packages/devextreme/js/__internal/events/gesture/m_swipeable.ts index 5238f91aa273..4ba1540119cd 100644 --- a/packages/devextreme/js/__internal/events/gesture/m_swipeable.ts +++ b/packages/devextreme/js/__internal/events/gesture/m_swipeable.ts @@ -21,8 +21,8 @@ const ACTION_TO_EVENT_MAP = { }; const IMMEDIATE_TIMEOUT = 180; - -const Swipeable = (DOMComponent as any).inherit({ +// @ts-expect-error +const Swipeable = DOMComponent.inherit({ _getDefaultOptions() { return extend(this.callBase(), { diff --git a/packages/devextreme/js/__internal/events/m_hold.ts b/packages/devextreme/js/__internal/events/m_hold.ts index 47d4691b4feb..f5fb13543588 100644 --- a/packages/devextreme/js/__internal/events/m_hold.ts +++ b/packages/devextreme/js/__internal/events/m_hold.ts @@ -34,7 +34,8 @@ const HoldEmitter = Emitter.inherit({ }, _touchWasMoved(e) { - const delta = eventDelta(this._startEventData, eventData(e) as any); + // @ts-expect-error + const delta = eventDelta(this._startEventData, eventData(e)); return abs(delta.x) > TOUCH_BOUNDARY || abs(delta.y) > TOUCH_BOUNDARY; }, diff --git a/packages/devextreme/js/__internal/events/m_pointer.ts b/packages/devextreme/js/__internal/events/m_pointer.ts index 07d45017649e..7b1f09b1aae5 100644 --- a/packages/devextreme/js/__internal/events/m_pointer.ts +++ b/packages/devextreme/js/__internal/events/m_pointer.ts @@ -24,8 +24,8 @@ const getStrategy = (support, { tablet, phone }) => { return MouseStrategy; }; - -const EventStrategy = getStrategy(support, devices.real() as any); +// @ts-expect-error +const EventStrategy = getStrategy(support, devices.real()); each(EventStrategy.map, (pointerEvent, originalEvents) => { registerEvent(pointerEvent, new EventStrategy(pointerEvent, originalEvents)); @@ -43,12 +43,13 @@ const pointer = { }; function getStrategyFromGlobalConfig() { - const eventStrategyName = GlobalConfig().pointerEventStrategy as any; + const eventStrategyName = GlobalConfig().pointerEventStrategy; return { 'mouse-and-touch': MouseAndTouchStrategy, touch: TouchStrategy, mouse: MouseStrategy, + // @ts-expect-error }[eventStrategyName]; } diff --git a/packages/devextreme/js/__internal/events/m_remove.ts b/packages/devextreme/js/__internal/events/m_remove.ts index 7f05a2b3b1e5..7db6f04f4725 100644 --- a/packages/devextreme/js/__internal/events/m_remove.ts +++ b/packages/devextreme/js/__internal/events/m_remove.ts @@ -13,7 +13,8 @@ beforeCleanData((elements) => { // @ts-expect-error if ($element.prop(eventPropName)) { $element[0][eventPropName] = null; - eventsEngine.triggerHandler($element, removeEvent as any); + // @ts-expect-error + eventsEngine.triggerHandler($element, removeEvent); } } }); diff --git a/packages/devextreme/js/__internal/events/pointer/m_mouse.ts b/packages/devextreme/js/__internal/events/pointer/m_mouse.ts index 37d8e05c96dd..87cf81e5e738 100644 --- a/packages/devextreme/js/__internal/events/pointer/m_mouse.ts +++ b/packages/devextreme/js/__internal/events/pointer/m_mouse.ts @@ -48,10 +48,14 @@ const MouseStrategy = BaseStrategy.inherit({ }, }); -(MouseStrategy as any).map = eventMap; -(MouseStrategy as any).normalize = normalizeMouseEvent; -(MouseStrategy as any).activate = activateStrategy; -(MouseStrategy as any).resetObserver = function () { +// @ts-expect-error +MouseStrategy.map = eventMap; +// @ts-expect-error +MouseStrategy.normalize = normalizeMouseEvent; +// @ts-expect-error +MouseStrategy.activate = activateStrategy; +// @ts-expect-error +MouseStrategy.resetObserver = function () { observer.reset(); }; diff --git a/packages/devextreme/js/__internal/events/pointer/m_mouse_and_touch.ts b/packages/devextreme/js/__internal/events/pointer/m_mouse_and_touch.ts index ad739214255b..ca198b4a1bf0 100644 --- a/packages/devextreme/js/__internal/events/pointer/m_mouse_and_touch.ts +++ b/packages/devextreme/js/__internal/events/pointer/m_mouse_and_touch.ts @@ -21,8 +21,8 @@ const activateStrategy = function () { if (activated) { return; } - - (MouseStrategy as any).activate(); + // @ts-expect-error + MouseStrategy.activate(); activated = true; }; @@ -66,7 +66,8 @@ const MouseAndTouchStrategy = BaseStrategy.inherit({ }, _fireEvent(args) { - const normalizer = isMouseEvent(args.originalEvent) ? (MouseStrategy as any).normalize : (TouchStrategy as any).normalize; + // @ts-expect-error + const normalizer = isMouseEvent(args.originalEvent) ? MouseStrategy.normalize : TouchStrategy.normalize; return this.callBase(extend(normalizer(args.originalEvent), args)); },