Unverified Commit 9f3fd5d7 authored by Steven's avatar Steven Committed by GitHub

chore: remove `as any` type cast (#54074)

This PR refactors some types to remove `as any`, but the runtime logic is the same.
parent 594f3d1f
......@@ -3125,15 +3125,15 @@ export default async function build(
const images = { ...config.images }
const { deviceSizes, imageSizes } = images
;(images as any).sizes = [...deviceSizes, ...imageSizes]
;(images as any).remotePatterns = (
config?.images?.remotePatterns || []
).map((p: RemotePattern) => ({
// Should be the same as matchRemotePattern()
protocol: p.protocol,
hostname: makeRe(p.hostname).source,
port: p.port,
pathname: makeRe(p.pathname ?? '**').source,
}))
images.remotePatterns = (config?.images?.remotePatterns || []).map(
(p: RemotePattern) => ({
// Should be the same as matchRemotePattern()
protocol: p.protocol,
hostname: makeRe(p.hostname).source,
port: p.port,
pathname: makeRe(p.pathname ?? '**').source,
})
)
await fs.writeFile(
path.join(distDir, IMAGES_MANIFEST),
......
......@@ -782,7 +782,8 @@ function bindingToApi(binding: any, _wasm: boolean) {
const routes = new Map()
for (const { pathname, ...nativeRoute } of entrypoints.routes) {
let route: Route
switch (nativeRoute.type) {
const routeType = nativeRoute.type
switch (routeType) {
case 'page':
route = {
type: 'page',
......@@ -815,11 +816,11 @@ function bindingToApi(binding: any, _wasm: boolean) {
}
break
default:
const _exhaustiveCheck: never = routeType
invariant(
nativeRoute,
() => `Unknown route type: ${(nativeRoute as any).type}`
() => `Unknown route type: ${_exhaustiveCheck}`
)
break
}
routes.set(pathname, route)
}
......
......@@ -6,18 +6,19 @@ export default function initializeBuildWatcher(
toggleCallback: any,
position = 'bottom-right'
) {
const shadowHost = document.createElement('div')
const type = 'div' as string
const shadowHost = document.createElement(type)
const [verticalProperty, horizontalProperty] = position.split('-')
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 as any).style[verticalProperty] = '10px'
shadowHost.style[verticalProperty as any] = '10px'
// Ensure container's position to be left or right (default)
;(shadowHost as any).style[horizontalProperty] = '20px'
;(shadowHost as any).style.width = 0
;(shadowHost as any).style.height = 0
;(shadowHost as any).style.zIndex = 99999
shadowHost.style[horizontalProperty as any] = '20px'
shadowHost.style.width = '0'
shadowHost.style.height = '0'
shadowHost.style.zIndex = '99999'
document.body.appendChild(shadowHost)
let shadowRoot
......
......@@ -548,8 +548,7 @@ export default async function exportApp(
const filteredPaths = exportPaths.filter(
// Remove API routes
(route) =>
(exportPathMap[route] as any)._isAppDir ||
!isAPIRoute(exportPathMap[route].page)
exportPathMap[route]._isAppDir || !isAPIRoute(exportPathMap[route].page)
)
if (filteredPaths.length !== exportPaths.length) {
......
......@@ -163,8 +163,8 @@ export default async function exportPage({
const { query: originalQuery = {} } = pathMap
const { page } = pathMap
const pathname = normalizeAppPath(page)
const isAppDir = (pathMap as any)._isAppDir
const isDynamicError = (pathMap as any)._isDynamicError
const isAppDir = Boolean(pathMap._isAppDir)
const isDynamicError = pathMap._isDynamicError
const filePath = normalizePagePath(path)
const isDynamic = isDynamicRoute(page)
const ampPath = `${filePath}.amp`
......
......@@ -569,7 +569,7 @@ async function loadRedirects(config: NextConfig) {
// save original redirects before transforms
if (Array.isArray(redirects)) {
;(config as any)._originalRedirects = redirects.map((r) => ({ ...r }))
config._originalRedirects = redirects.map((r) => ({ ...r }))
}
redirects = processRoutes(redirects, config, 'redirect')
checkCustomRoutes(redirects, 'redirect')
......@@ -610,7 +610,7 @@ async function loadRewrites(config: NextConfig) {
checkCustomRoutes(fallback, 'rewrite')
// save original rewrites before transforms
;(config as any)._originalRewrites = {
config._originalRewrites = {
beforeFiles: beforeFiles.map((r) => ({ ...r })),
afterFiles: afterFiles.map((r) => ({ ...r })),
fallback: fallback.map((r) => ({ ...r })),
......
......@@ -14,7 +14,8 @@ export function OpenGraphMetadata({
let typedOpenGraph
if ('type' in openGraph) {
switch (openGraph.type) {
const openGraphType = openGraph.type
switch (openGraphType) {
case 'website':
typedOpenGraph = [Meta({ property: 'og:type', content: 'website' })]
break
......@@ -185,7 +186,8 @@ export function OpenGraphMetadata({
break
default:
throw new Error('Invalid OpenGraph type: ' + (openGraph as any).type)
const _exhaustiveCheck: never = openGraphType
throw new Error(`Invalid OpenGraph type: ${_exhaustiveCheck}`)
}
}
......
......@@ -6,9 +6,8 @@ Files in the rsc directory are meant to be packaged as part of the RSC graph usi
import ReactDOM from 'react-dom'
const stylePreloadOptions = { as: 'style' }
export function preloadStyle(href: string) {
;(ReactDOM as any).preload(href, stylePreloadOptions)
ReactDOM.preload(href, { as: 'style' })
}
export function preloadFont(href: string, type: string) {
......
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