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