Skip to content

Commit

Permalink
fix(preload-langs): πŸ› remove type declaration conflict
Browse files Browse the repository at this point in the history
The requestIdleCallback type is conflicting with the one provided in
typescript v4.4+

βœ… Closes: #510
  • Loading branch information
shaharkazaz committed Sep 30, 2021
1 parent 1b2a18c commit 7331c32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
17 changes: 4 additions & 13 deletions libs/transloco-preload-langs/src/lib/preload-langs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,8 @@ interface IdleDeadline {
timeRemaining: () => number;
}

type IdleCallback = (deadLine: IdleDeadline) => void;

declare global {
interface Window {
requestIdleCallback: (cb: IdleCallback) => number;
cancelIdleCallback: (id: number) => void;
}
}

window.requestIdleCallback =
window.requestIdleCallback ||
(window as any).requestIdleCallback =
(window as any).requestIdleCallback ||
function (cb: (deadLine: IdleDeadline) => void) {
const start = Date.now();

Expand All @@ -33,8 +24,8 @@ window.requestIdleCallback =
}, 1);
};

window.cancelIdleCallback =
window.cancelIdleCallback ||
(window as any).cancelIdleCallback =
(window as any).cancelIdleCallback ||
function (id: number) {
clearTimeout(id);
};
Expand Down
4 changes: 2 additions & 2 deletions libs/transloco-preload-langs/src/lib/preload-langs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TranslocoPreloadLangsService implements OnDestroy {
) {
if (!langs) return;

this.idleCallbackId = window.requestIdleCallback(() => {
this.idleCallbackId = (window as any).requestIdleCallback(() => {
const preloads = langs.map((currentLangOrScope) => {
const lang = service._completeScopeWithLang(currentLangOrScope);

Expand All @@ -39,7 +39,7 @@ export class TranslocoPreloadLangsService implements OnDestroy {

ngOnDestroy() {
if (this.idleCallbackId !== undefined) {
window.cancelIdleCallback(this.idleCallbackId);
(window as any).cancelIdleCallback(this.idleCallbackId);
}
this.subscription?.unsubscribe();
// Caretaker note: it's important to clean up references to subscriptions since they save the `next`
Expand Down

0 comments on commit 7331c32

Please sign in to comment.