Unverified Commit 0e65335a authored by Sukka's avatar Sukka Committed by GitHub

types: better type definition for internal utils (#43070)

The PR removes some `as unknown as` assertions by improving type
definitions.
parent 9fce9964
......@@ -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])
......
......@@ -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
}
......
......@@ -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 =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment