Skip to content

Commit 6d8125f

Browse files
committed
Flag excess properties in Next.js config with TypeScript
1 parent 9d0ab60 commit 6d8125f

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ export default async function getBaseWebpackConfig(
24602460
assetPrefix: config.assetPrefix || '',
24612461
sassOptions: config.sassOptions,
24622462
productionBrowserSourceMaps: config.productionBrowserSourceMaps,
2463-
future: config.future,
2463+
future: (config as any).future,
24642464
experimental: config.experimental,
24652465
disableStaticImages: config.images.disableStaticImages,
24662466
transpilePackages: config.transpilePackages,
@@ -2637,8 +2637,8 @@ export default async function getBaseWebpackConfig(
26372637
}
26382638

26392639
// Backwards compat with webpack-dev-middleware options object
2640-
if (typeof config.webpackDevMiddleware === 'function') {
2641-
const options = config.webpackDevMiddleware({
2640+
if (typeof (config as any).webpackDevMiddleware === 'function') {
2641+
const options = (config as any).webpackDevMiddleware({
26422642
watchOptions: webpackConfig.watchOptions,
26432643
})
26442644
if (options.watchOptions) {

packages/next/src/build/webpack/config/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ export async function buildConfiguration(
3939
sassOptions: any
4040
productionBrowserSourceMaps: boolean
4141
transpilePackages: NextConfigComplete['transpilePackages']
42+
// @ts-expect-error TODO: remove any
4243
future: NextConfigComplete['future']
4344
experimental: NextConfigComplete['experimental']
44-
disableStaticImages: NextConfigComplete['disableStaticImages']
45+
disableStaticImages: NextConfigComplete['images']['disableStaticImages']
4546
serverSourceMaps: NextConfigComplete['experimental']['serverSourceMaps']
4647
}
4748
): Promise<webpack.Configuration> {

packages/next/src/build/webpack/config/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type ConfigurationContext = {
2626

2727
transpilePackages: NextConfigComplete['transpilePackages']
2828

29+
// @ts-expect-error TODO: remove any
2930
future: NextConfigComplete['future']
3031
experimental: NextConfigComplete['experimental']
3132
}

packages/next/src/export/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async function exportAppImpl(
127127
)
128128
}
129129

130-
const customRoutes = ['rewrites', 'redirects', 'headers'].filter(
130+
const customRoutes = (['rewrites', 'redirects', 'headers'] as const).filter(
131131
(config) => typeof nextConfig[config] === 'function'
132132
)
133133

packages/next/src/server/config-shared.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ import { INFINITE_CACHE } from '../lib/constants'
1616
import { isStableBuild } from '../shared/lib/canary-only'
1717
import type { FallbackRouteParam } from '../build/static-paths/types'
1818

19-
export type NextConfigComplete = Required<NextConfig> & {
19+
export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & {
2020
images: Required<ImageConfigComplete>
2121
typescript: TypeScriptConfig
22-
configOrigin?: string
23-
configFile?: string
22+
configFile: string | undefined
2423
configFileName: string
2524
// override NextConfigComplete.experimental.htmlLimitedBots to string
2625
// because it's not defined in NextConfigComplete.experimental
@@ -889,7 +888,7 @@ export type ExportPathMap = {
889888
*
890889
* Read more: [Next.js Docs: `next.config.js`](https://nextjs.org/docs/app/api-reference/config/next-config-js)
891890
*/
892-
export interface NextConfig extends Record<string, any> {
891+
export interface NextConfig {
893892
allowedDevOrigins?: string[]
894893

895894
exportPathMap?: (
@@ -1318,6 +1317,26 @@ export interface NextConfig extends Record<string, any> {
13181317
* /Mediapartners-Google|Slurp|DuckDuckBot|baiduspider|yandex|sogou|bitlybot|tumblr|vkShare|quora link preview|redditbot|ia_archiver|Bingbot|BingPreview|applebot|facebookexternalhit|facebookcatalog|Twitterbot|LinkedInBot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview/i
13191318
*/
13201319
htmlLimitedBots?: RegExp
1320+
1321+
/**
1322+
* @internal
1323+
*/
1324+
configFile?: string | undefined
1325+
1326+
/**
1327+
* @internal
1328+
*/
1329+
configOrigin?: string | undefined
1330+
1331+
/**
1332+
* @internal
1333+
*/
1334+
_originalRedirects?: any
1335+
1336+
/**
1337+
* @internal
1338+
*/
1339+
_originalRewrites?: any
13211340
}
13221341

13231342
export const defaultConfig = Object.freeze({

packages/next/src/server/config.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export function warnOptionHasBeenDeprecated(
7777
let found = true
7878
const nestedPropertyKeys = nestedPropertyKey.split('.')
7979
for (const key of nestedPropertyKeys) {
80-
if (current[key] !== undefined) {
81-
current = current[key]
80+
if ((current as any)[key] !== undefined) {
81+
current = (current as any)[key]
8282
} else {
8383
found = false
8484
break
@@ -168,10 +168,12 @@ export function warnOptionHasBeenMovedOutOfExperimental(
168168
const newKeys = newKey.split('.')
169169
while (newKeys.length > 1) {
170170
const key = newKeys.shift()!
171-
current[key] = current[key] || {}
172-
current = current[key]
171+
;(current as any)[key] = (current as any)[key] || {}
172+
current = (current as any)[key]
173173
}
174-
current[newKeys.shift()!] = (config.experimental as any)[oldExperimentalKey]
174+
;(current as any)[newKeys.shift()!] = (config.experimental as any)[
175+
oldExperimentalKey
176+
]
175177
}
176178

177179
return config
@@ -193,7 +195,7 @@ function warnCustomizedOption(
193195
if (!(seg in current)) {
194196
return
195197
}
196-
current = current[seg]
198+
current = (current as any)[seg]
197199
}
198200

199201
if (!silent && current !== defaultValue) {
@@ -219,16 +221,16 @@ function assignDefaultsAndValidate(
219221
phase: PHASE_TYPE
220222
): NextConfigComplete {
221223
const configFileName = userConfig.configFileName
222-
if (typeof userConfig.exportTrailingSlash !== 'undefined') {
224+
if (typeof (userConfig as any).exportTrailingSlash !== 'undefined') {
223225
if (!silent) {
224226
Log.warn(
225227
`The "exportTrailingSlash" option has been renamed to "trailingSlash". Please update your ${configFileName}.`
226228
)
227229
}
228230
if (typeof userConfig.trailingSlash === 'undefined') {
229-
userConfig.trailingSlash = userConfig.exportTrailingSlash
231+
userConfig.trailingSlash = (userConfig as any).exportTrailingSlash
230232
}
231-
delete userConfig.exportTrailingSlash
233+
delete (userConfig as any).exportTrailingSlash
232234
}
233235

234236
// Handle migration of experimental.dynamicIO to experimental.cacheComponents
@@ -246,7 +248,7 @@ function assignDefaultsAndValidate(
246248

247249
const config = Object.keys(userConfig).reduce<{ [key: string]: any }>(
248250
(currentConfig, key) => {
249-
const value = userConfig[key]
251+
const value = (userConfig as any)[key]
250252

251253
if (value === undefined || value === null) {
252254
return currentConfig
@@ -1482,7 +1484,7 @@ export default async function loadConfig(
14821484
validateConfigSchema(userConfig, configFileName, curLog.warn)
14831485
}
14841486

1485-
if (userConfig.target && userConfig.target !== 'server') {
1487+
if ((userConfig as any).target && (userConfig as any).target !== 'server') {
14861488
throw new Error(
14871489
`The "target" property is no longer supported in ${configFileName}.\n` +
14881490
'See more info here https://nextjs.org/docs/messages/deprecated-target-config'
@@ -1580,7 +1582,7 @@ export default async function loadConfig(
15801582
silent,
15811583
configuredExperimentalFeatures,
15821584
phase
1583-
) as NextConfigComplete
1585+
)
15841586

15851587
const finalConfig = await applyModifyConfig(completeConfig, phase, silent)
15861588

0 commit comments

Comments
 (0)