Skip to content

Commit

Permalink
types: better type definition for internal utils (#43070)
Browse files Browse the repository at this point in the history
The PR removes some `as unknown as` assertions by improving type
definitions.
  • Loading branch information
SukkaW committed Nov 20, 2022
1 parent 9fce996 commit 0e65335
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/next/client/components/app-router.tsx
Expand Up @@ -168,7 +168,7 @@ function Router({
// This is safe to do as canonicalUrl can't be rendered, it's only used to control the history updates in the useEffect further down in this file.
typeof window !== 'undefined'
? // window.location does not have the same type as URL but has all the fields createHrefFromUrl needs.
createHrefFromUrl(window.location as unknown as URL)
createHrefFromUrl(window.location)
: initialCanonicalUrl,
}
}, [children, initialCanonicalUrl, initialTree])
Expand Down
4 changes: 3 additions & 1 deletion packages/next/client/components/reducer.ts
Expand Up @@ -45,7 +45,9 @@ function readRecordValue<T>(thenable: Promise<T>): T {
}
}

export function createHrefFromUrl(url: URL): string {
export function createHrefFromUrl(
url: Pick<URL, 'pathname' | 'search' | 'hash'>
): string {
return url.pathname + url.search + url.hash
}

Expand Down
4 changes: 2 additions & 2 deletions packages/next/client/request-idle-callback.ts
Expand Up @@ -4,14 +4,14 @@ export const requestIdleCallback =
self.requestIdleCallback.bind(window)) ||
function (cb: IdleRequestCallback): number {
let start = Date.now()
return setTimeout(function () {
return self.setTimeout(function () {
cb({
didTimeout: false,
timeRemaining: function () {
return Math.max(0, 50 - (Date.now() - start))
},
})
}, 1) as unknown as number
}, 1)
}

export const cancelIdleCallback =
Expand Down

0 comments on commit 0e65335

Please sign in to comment.