Skip to content

Commit 59b7f43

Browse files
committedNov 25, 2024·
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 26a817c)
1 parent a312014 commit 59b7f43

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed
 

‎src/cdk/a11y/focus-monitor/focus-monitor.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export class FocusMonitor implements OnDestroy {
9898
private _windowFocused = false;
9999

100100
/** The timeout id of the window focus timeout. */
101-
private _windowFocusTimeoutId: number;
101+
private _windowFocusTimeoutId: ReturnType<typeof setTimeout>;
102102

103103
/** The timeout id of the origin clearing timeout. */
104-
private _originTimeoutId: number;
104+
private _originTimeoutId: ReturnType<typeof setTimeout>;
105105

106106
/**
107107
* Whether the origin was determined via a touch interaction. Necessary as properly attributing
@@ -137,7 +137,7 @@ export class FocusMonitor implements OnDestroy {
137137
// Make a note of when the window regains focus, so we can
138138
// restore the origin info for the focused element.
139139
this._windowFocused = true;
140-
this._windowFocusTimeoutId = window.setTimeout(() => (this._windowFocused = false));
140+
this._windowFocusTimeoutId = setTimeout(() => (this._windowFocused = false));
141141
};
142142

143143
/** Used to reference correct document/window */

‎src/cdk/a11y/live-announcer/live-announcer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class LiveAnnouncer implements OnDestroy {
2929

3030
private _liveElement: HTMLElement;
3131
private _document = inject(DOCUMENT);
32-
private _previousTimeout: number;
32+
private _previousTimeout: ReturnType<typeof setTimeout>;
3333
private _currentPromise: Promise<void> | undefined;
3434
private _currentResolve: (() => void) | undefined;
3535

‎src/material/bottom-sheet/bottom-sheet-ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class MatBottomSheetRef<T = any, R = any> {
4747
private _result: R | undefined;
4848

4949
/** Handle to the timeout that's running as a fallback in case the exit animation doesn't fire. */
50-
private _closeFallbackTimeout: number;
50+
private _closeFallbackTimeout: ReturnType<typeof setTimeout>;
5151

5252
constructor(
5353
private _ref: DialogRef<R, T>,

‎src/material/dialog/dialog-ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class MatDialogRef<T, R = any> {
5252
private _result: R | undefined;
5353

5454
/** Handle to the timeout that's running as a fallback in case the exit animation doesn't fire. */
55-
private _closeFallbackTimeout: number;
55+
private _closeFallbackTimeout: ReturnType<typeof setTimeout>;
5656

5757
/** Current state of the dialog. */
5858
private _state = MatDialogState.OPEN;

‎src/material/snack-bar/snack-bar-container.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
7070
private readonly _announceDelay: number = 150;
7171

7272
/** The timeout for announcing the snack bar's content. */
73-
private _announceTimeoutId: number;
73+
private _announceTimeoutId: ReturnType<typeof setTimeout>;
7474

7575
/** Whether the component has been destroyed. */
7676
private _destroyed = false;

‎src/material/snack-bar/snack-bar-ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class MatSnackBarRef<T> {
4545
* Timeout ID for the duration setTimeout call. Used to clear the timeout if the snackbar is
4646
* dismissed before the duration passes.
4747
*/
48-
private _durationTimeoutId: number;
48+
private _durationTimeoutId: ReturnType<typeof setTimeout>;
4949

5050
/** Whether the snack bar was dismissed using the action button. */
5151
private _dismissedByAction = false;

0 commit comments

Comments
 (0)
Please sign in to comment.