Skip to content

Commit

Permalink
chore: improve ts types for position in dev-build-watcher (#54124)
Browse files Browse the repository at this point in the history
- Follow up to #54074
  • Loading branch information
styfle committed Aug 17, 2023
1 parent df1de76 commit 3fadba5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/next/src/client/dev/dev-build-watcher.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3fadba5

Please sign in to comment.