From 8f4e265f76db4480576e9b7a3223853946f74f19 Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Mon, 6 Apr 2020 08:59:44 -0700 Subject: [PATCH] Fix Utility Types (#11077) --- packages/next/build/plugins/collect-plugins.ts | 9 +-------- packages/next/next-server/lib/utils.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/packages/next/build/plugins/collect-plugins.ts b/packages/next/build/plugins/collect-plugins.ts index cbfe00ea60731..efd0510410f39 100644 --- a/packages/next/build/plugins/collect-plugins.ts +++ b/packages/next/build/plugins/collect-plugins.ts @@ -134,11 +134,6 @@ async function collectPluginMeta( } } -type SeparatedPlugins = { - appMiddlewarePlugins: PluginMetaData[] - documentMiddlewarePlugins: PluginMetaData[] -} - // clean package name so it can be used as variable export const getPluginId = (pkg: string): string => { pkg = pkg.replace(/\W/g, '') @@ -254,6 +249,4 @@ async function _collectPlugins( // only execute it once between server/client configs // since the plugins need to match -export const collectPlugins = execOnce( - _collectPlugins -) as typeof _collectPlugins +export const collectPlugins = execOnce(_collectPlugins) diff --git a/packages/next/next-server/lib/utils.ts b/packages/next/next-server/lib/utils.ts index cda428cb9a050..514cb0d223c03 100644 --- a/packages/next/next-server/lib/utils.ts +++ b/packages/next/next-server/lib/utils.ts @@ -239,17 +239,19 @@ export type NextApiHandler = ( /** * Utils */ -export function execOnce(this: any, fn: (...args: any) => any) { +export function execOnce ReturnType>( + fn: T +): T { let used = false - let result: any = null + let result: ReturnType - return (...args: any) => { + return ((...args: any[]) => { if (!used) { used = true - result = fn.apply(this, args) + result = fn(...args) } return result - } + }) as T } export function getLocationOrigin() { @@ -263,7 +265,7 @@ export function getURL() { return href.substring(origin.length) } -export function getDisplayName(Component: ComponentType) { +export function getDisplayName

(Component: ComponentType

) { return typeof Component === 'string' ? Component : Component.displayName || Component.name || 'Unknown' @@ -296,7 +298,7 @@ export async function loadGetInitialProps< pageProps: await loadGetInitialProps(ctx.Component, ctx.ctx), } } - return {} as any + return {} as IP } const props = await App.getInitialProps(ctx) @@ -356,7 +358,7 @@ export function formatWithValidation( } } - return format(url as any, options) + return format(url as URL, options) } export const SP = typeof performance !== 'undefined'