Skip to content

Commit b475810

Browse files
committed
fix: remove 'any' types from next's response proxy
1 parent e88dd8c commit b475810

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/run/revalidate.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import type { ServerResponse } from 'node:http'
22
import { isPromise } from 'node:util/types'
33

4+
import type { NextApiResponse } from 'next'
5+
46
import type { RequestContext } from './handlers/request-context.cjs'
57

8+
type ResRevalidateMethod = NextApiResponse['revalidate']
9+
10+
function isRevalidateMethod(
11+
key: string,
12+
nextResponseField: unknown,
13+
): nextResponseField is ResRevalidateMethod {
14+
return key === 'revalidate' && typeof nextResponseField === 'function'
15+
}
16+
617
// Needing to proxy the response object to intercept the revalidate call for on-demand revalidation on page routes
718
export const nextResponseProxy = (res: ServerResponse, requestContext: RequestContext) => {
819
return new Proxy(res, {
9-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10-
get(target: any[string], key: string) {
11-
const originalValue = target[key]
12-
if (key === 'revalidate') {
13-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14-
return async function newRevalidate(...args: any[]) {
20+
get(target: ServerResponse, key: string) {
21+
const originalValue = Reflect.get(target, key)
22+
if (isRevalidateMethod(key, originalValue)) {
23+
return function newRevalidate(...args: Parameters<ResRevalidateMethod>) {
1524
requestContext.didPagesRouterOnDemandRevalidate = true
1625

17-
const result = originalValue?.apply(target, args)
26+
const result = originalValue.apply(target, args)
1827
if (result && isPromise(result)) {
1928
requestContext.trackBackgroundWork(result)
2029
}

0 commit comments

Comments
 (0)