Skip to content

Commit

Permalink
fix(multiple): use cross-compatible type for setTimeout (#30073)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
crisbeto committed Nov 25, 2024
1 parent a312014 commit 59b7f43
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout>;

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

/**
* Whether the origin was determined via a touch interaction. Necessary as properly attributing
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/a11y/live-announcer/live-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class LiveAnnouncer implements OnDestroy {

private _liveElement: HTMLElement;
private _document = inject(DOCUMENT);
private _previousTimeout: number;
private _previousTimeout: ReturnType<typeof setTimeout>;
private _currentPromise: Promise<void> | undefined;
private _currentResolve: (() => void) | undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/material/bottom-sheet/bottom-sheet-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class MatBottomSheetRef<T = any, R = any> {
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<typeof setTimeout>;

constructor(
private _ref: DialogRef<R, T>,
Expand Down
2 changes: 1 addition & 1 deletion src/material/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class MatDialogRef<T, R = any> {
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<typeof setTimeout>;

/** Current state of the dialog. */
private _state = MatDialogState.OPEN;
Expand Down
2 changes: 1 addition & 1 deletion src/material/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout>;

/** Whether the component has been destroyed. */
private _destroyed = false;
Expand Down
2 changes: 1 addition & 1 deletion src/material/snack-bar/snack-bar-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MatSnackBarRef<T> {
* 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<typeof setTimeout>;

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

0 comments on commit 59b7f43

Please sign in to comment.