Unverified Commit 3fadba5a authored by Steven's avatar Steven Committed by GitHub

chore: improve ts types for `position` in `dev-build-watcher` (#54124)

- Follow up to https://github.com/vercel/next.js/pull/54074
parent df1de76c
// 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)
......
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