From 3fadba5aba5d4fcc217cd869ddd6d20b27b947c8 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 17 Aug 2023 11:36:35 -0400 Subject: [PATCH] chore: improve ts types for `position` in `dev-build-watcher` (#54124) - Follow up to https://github.com/vercel/next.js/pull/54074 --- .../next/src/client/dev/dev-build-watcher.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/next/src/client/dev/dev-build-watcher.ts b/packages/next/src/client/dev/dev-build-watcher.ts index da9a0b238b9cb..e9897a8216edc 100644 --- a/packages/next/src/client/dev/dev-build-watcher.ts +++ b/packages/next/src/client/dev/dev-build-watcher.ts @@ -1,21 +1,26 @@ -// TODO: Remove use of `any` type. Fix no-use-before-define violations. /* eslint-disable @typescript-eslint/no-use-before-define */ import { addMessageListener } from './error-overlay/websocket' +type VerticalPosition = 'top' | 'bottom' +type HorizonalPosition = 'left' | 'right' + export default function initializeBuildWatcher( - toggleCallback: any, + toggleCallback: (cb: (event: string | { data: string }) => void) => void, position = 'bottom-right' ) { const type = 'div' as string const shadowHost = document.createElement(type) - const [verticalProperty, horizontalProperty] = position.split('-') + const [verticalProperty, horizontalProperty] = position.split('-') as [ + VerticalPosition, + HorizonalPosition + ] shadowHost.id = '__next-build-watcher' // Make sure container is fixed and on a high zIndex so it shows shadowHost.style.position = 'fixed' // Ensure container's position to be top or bottom (default) - shadowHost.style[verticalProperty as any] = '10px' + shadowHost.style[verticalProperty] = '10px' // Ensure container's position to be left or right (default) - shadowHost.style[horizontalProperty as any] = '20px' + shadowHost.style[horizontalProperty] = '20px' shadowHost.style.width = '0' shadowHost.style.height = '0' shadowHost.style.zIndex = '99999' @@ -60,7 +65,7 @@ export default function initializeBuildWatcher( } catch {} }) - function handleMessage(event: any) { + function handleMessage(event: string | { data: string }) { const obj = typeof event === 'string' ? { action: event } : JSON.parse(event.data)