Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: better type definition for internal utils #43070

Merged
merged 4 commits into from Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 () {
Copy link
Contributor Author

@SukkaW SukkaW Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@types/node doesn't overload setTimeout on globalThis, so self.setTimeout will always return the number type.

cb({
didTimeout: false,
timeRemaining: function () {
return Math.max(0, 50 - (Date.now() - start))
},
})
}, 1) as unknown as number
}, 1)
}

export const cancelIdleCallback =
Expand Down