From 59b7f436acc5c4b2e732ec09ac44e031e8b422bf Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 25 Nov 2024 14:09:51 +0100 Subject: [PATCH] fix(multiple): use cross-compatible type for setTimeout (#30073) Fixes that some places were raising an error due to the return type of `setTimeout` being different between the browser and Node. (cherry picked from commit 26a817ccb3b7391b1baed6693adfb80a88cdd9c1) --- src/cdk/a11y/focus-monitor/focus-monitor.ts | 6 +++--- src/cdk/a11y/live-announcer/live-announcer.ts | 2 +- src/material/bottom-sheet/bottom-sheet-ref.ts | 2 +- src/material/dialog/dialog-ref.ts | 2 +- src/material/snack-bar/snack-bar-container.ts | 2 +- src/material/snack-bar/snack-bar-ref.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cdk/a11y/focus-monitor/focus-monitor.ts b/src/cdk/a11y/focus-monitor/focus-monitor.ts index 51a21cf68d6b..ef34ed52694b 100644 --- a/src/cdk/a11y/focus-monitor/focus-monitor.ts +++ b/src/cdk/a11y/focus-monitor/focus-monitor.ts @@ -98,10 +98,10 @@ export class FocusMonitor implements OnDestroy { private _windowFocused = false; /** The timeout id of the window focus timeout. */ - private _windowFocusTimeoutId: number; + private _windowFocusTimeoutId: ReturnType; /** The timeout id of the origin clearing timeout. */ - private _originTimeoutId: number; + private _originTimeoutId: ReturnType; /** * Whether the origin was determined via a touch interaction. Necessary as properly attributing @@ -137,7 +137,7 @@ export class FocusMonitor implements OnDestroy { // Make a note of when the window regains focus, so we can // restore the origin info for the focused element. this._windowFocused = true; - this._windowFocusTimeoutId = window.setTimeout(() => (this._windowFocused = false)); + this._windowFocusTimeoutId = setTimeout(() => (this._windowFocused = false)); }; /** Used to reference correct document/window */ diff --git a/src/cdk/a11y/live-announcer/live-announcer.ts b/src/cdk/a11y/live-announcer/live-announcer.ts index ed16913ffd96..91cd457f6812 100644 --- a/src/cdk/a11y/live-announcer/live-announcer.ts +++ b/src/cdk/a11y/live-announcer/live-announcer.ts @@ -29,7 +29,7 @@ export class LiveAnnouncer implements OnDestroy { private _liveElement: HTMLElement; private _document = inject(DOCUMENT); - private _previousTimeout: number; + private _previousTimeout: ReturnType; private _currentPromise: Promise | undefined; private _currentResolve: (() => void) | undefined; diff --git a/src/material/bottom-sheet/bottom-sheet-ref.ts b/src/material/bottom-sheet/bottom-sheet-ref.ts index 6e664c2ed282..093b4cd50dce 100644 --- a/src/material/bottom-sheet/bottom-sheet-ref.ts +++ b/src/material/bottom-sheet/bottom-sheet-ref.ts @@ -47,7 +47,7 @@ export class MatBottomSheetRef { private _result: R | undefined; /** Handle to the timeout that's running as a fallback in case the exit animation doesn't fire. */ - private _closeFallbackTimeout: number; + private _closeFallbackTimeout: ReturnType; constructor( private _ref: DialogRef, diff --git a/src/material/dialog/dialog-ref.ts b/src/material/dialog/dialog-ref.ts index 2017f67560bf..b20a6936ac68 100644 --- a/src/material/dialog/dialog-ref.ts +++ b/src/material/dialog/dialog-ref.ts @@ -52,7 +52,7 @@ export class MatDialogRef { private _result: R | undefined; /** Handle to the timeout that's running as a fallback in case the exit animation doesn't fire. */ - private _closeFallbackTimeout: number; + private _closeFallbackTimeout: ReturnType; /** Current state of the dialog. */ private _state = MatDialogState.OPEN; diff --git a/src/material/snack-bar/snack-bar-container.ts b/src/material/snack-bar/snack-bar-container.ts index 0f205c075058..9180b4aaefe9 100644 --- a/src/material/snack-bar/snack-bar-container.ts +++ b/src/material/snack-bar/snack-bar-container.ts @@ -70,7 +70,7 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy private readonly _announceDelay: number = 150; /** The timeout for announcing the snack bar's content. */ - private _announceTimeoutId: number; + private _announceTimeoutId: ReturnType; /** Whether the component has been destroyed. */ private _destroyed = false; diff --git a/src/material/snack-bar/snack-bar-ref.ts b/src/material/snack-bar/snack-bar-ref.ts index 40f9cefb1f35..b5eaad9ab629 100644 --- a/src/material/snack-bar/snack-bar-ref.ts +++ b/src/material/snack-bar/snack-bar-ref.ts @@ -45,7 +45,7 @@ export class MatSnackBarRef { * Timeout ID for the duration setTimeout call. Used to clear the timeout if the snackbar is * dismissed before the duration passes. */ - private _durationTimeoutId: number; + private _durationTimeoutId: ReturnType; /** Whether the snack bar was dismissed using the action button. */ private _dismissedByAction = false;