Skip to content

Commit 2fb06b6

Browse files
committed
chore(HMR clients): Fix a bunch of typescript errors by including the appropriate webpack type declarations
1 parent bfef1f4 commit 2fb06b6

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

packages/next/src/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoLinkTag.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="webpack/module.d.ts" />
2+
13
const getTarget = (() => {
24
const memo: any = {}
35

@@ -27,8 +29,6 @@ const getTarget = (() => {
2729
}
2830
})()
2931

30-
declare let __webpack_nonce__: string
31-
3232
module.exports = (url: any, options: any) => {
3333
options = options || {}
3434
options.attributes =

packages/next/src/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoStyleTag.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="webpack/module.d.ts" />
2+
13
const isOldIE = (function isOldIE() {
24
let memo: any
35

packages/next/src/client/components/react-dev-overlay/app/hot-reloader-client.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="webpack/module.d.ts" />
2+
13
import type { ReactNode } from 'react'
24
import { useCallback, useEffect, startTransition, useMemo, useRef } from 'react'
35
import stripAnsi from 'next/dist/compiled/strip-ansi'
@@ -120,7 +122,6 @@ function isUpdateAvailable() {
120122

121123
// Webpack disallows updates in other states.
122124
function canApplyUpdates() {
123-
// @ts-expect-error module.hot exists
124125
return module.hot.status() === 'idle'
125126
}
126127
function afterApplyUpdates(fn: any) {
@@ -129,12 +130,10 @@ function afterApplyUpdates(fn: any) {
129130
} else {
130131
function handler(status: any) {
131132
if (status === 'idle') {
132-
// @ts-expect-error module.hot exists
133133
module.hot.removeStatusHandler(handler)
134134
fn()
135135
}
136136
}
137-
// @ts-expect-error module.hot exists
138137
module.hot.addStatusHandler(handler)
139138
}
140139
}
@@ -213,7 +212,6 @@ function tryApplyUpdates(
213212
}
214213

215214
// https://webpack.js.org/api/hot-module-replacement/#check
216-
// @ts-expect-error module.hot exists
217215
module.hot
218216
.check(/* autoApply */ false)
219217
.then((updatedModules: any[] | null) => {
@@ -226,7 +224,6 @@ function tryApplyUpdates(
226224
onBeforeUpdate(hasUpdates)
227225
}
228226
// https://webpack.js.org/api/hot-module-replacement/#apply
229-
// @ts-expect-error module.hot exists
230227
return module.hot.apply()
231228
})
232229
.then(

packages/next/src/client/components/react-dev-overlay/pages/hot-reloader-client.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
// can be found here:
2929
// https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-dev-utils/webpackHotDevClient.js
3030

31+
/// <reference types="webpack/module.d.ts" />
32+
3133
import {
3234
register,
3335
onBuildError,
@@ -67,7 +69,6 @@ import {
6769
// https://github.com/glenjamin/webpack-hot-middleware
6870

6971
declare global {
70-
const __webpack_hash__: string
7172
interface Window {
7273
__nextDevClientId: number
7374
}
@@ -406,7 +407,6 @@ function isUpdateAvailable() {
406407

407408
// Webpack disallows updates in other states.
408409
function canApplyUpdates() {
409-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
410410
return module.hot.status() === 'idle'
411411
}
412412
function afterApplyUpdates(fn: () => void) {
@@ -415,12 +415,10 @@ function afterApplyUpdates(fn: () => void) {
415415
} else {
416416
function handler(status: string) {
417417
if (status === 'idle') {
418-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
419418
module.hot.removeStatusHandler(handler)
420419
fn()
421420
}
422421
}
423-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
424422
module.hot.addStatusHandler(handler)
425423
}
426424
}
@@ -430,7 +428,6 @@ function tryApplyUpdates(
430428
onBeforeHotUpdate: ((updatedModules: string[]) => unknown) | undefined,
431429
onHotUpdateSuccess: (updatedModules: string[]) => unknown
432430
) {
433-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
434431
if (!module.hot) {
435432
// HotModuleReplacementPlugin is not in Webpack configuration.
436433
console.error('HotModuleReplacementPlugin is not in Webpack configuration.')
@@ -480,7 +477,6 @@ function tryApplyUpdates(
480477
}
481478

482479
// https://webpack.js.org/api/hot-module-replacement/#check
483-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
484480
module.hot
485481
.check(/* autoApply */ false)
486482
.then((updatedModules: any) => {
@@ -491,7 +487,6 @@ function tryApplyUpdates(
491487
if (typeof onBeforeHotUpdate === 'function') {
492488
onBeforeHotUpdate(updatedModules)
493489
}
494-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
495490
return module.hot.apply()
496491
})
497492
.then(

packages/next/src/client/dev/amp-dev.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../server/dev/hot-reloader-types'
99
import { reportInvalidHmrMessage } from '../components/react-dev-overlay/shared'
1010

11-
declare global {
12-
const __webpack_runtime_id__: string
13-
}
11+
/// <reference types="webpack/module.d.ts" />
1412

1513
const data = JSON.parse(
1614
(document.getElementById('__NEXT_DATA__') as any).textContent
@@ -35,7 +33,6 @@ function isUpdateAvailable() {
3533

3634
// Webpack disallows updates in other states.
3735
function canApplyUpdates() {
38-
// @ts-expect-error TODO: module.hot exists but type needs to be added. Can't use `as any` here as webpack parses for `module.hot` calls.
3936
return module.hot.status() === 'idle'
4037
}
4138

packages/next/src/pages/_document.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="webpack/module.d.ts" />
2+
13
import React, { type JSX } from 'react'
24
import { NEXT_BUILTIN_DOCUMENT } from '../shared/lib/constants'
35
import type {
@@ -214,10 +216,10 @@ function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) {
214216
if (!nextScriptWorkers || process.env.NEXT_RUNTIME === 'edge') return null
215217

216218
try {
217-
let {
218-
partytownSnippet,
219-
// @ts-ignore: Prevent webpack from processing this require
220-
} = __non_webpack_require__('@builder.io/partytown/integration'!)
219+
// @ts-expect-error: Prevent webpack from processing this require
220+
let { partytownSnippet } = __non_webpack_require__(
221+
'@builder.io/partytown/integration'!
222+
)
221223

222224
const children = Array.isArray(props.children)
223225
? props.children

0 commit comments

Comments
 (0)