1
1
import type { ErrorPayload , HMRPayload , Update } from 'types/hmrPayload'
2
- import type { ViteHotContext } from 'types/hot'
2
+ import type { ModuleNamespace , ViteHotContext } from 'types/hot'
3
3
import type { InferCustomEventPayload } from 'types/customEvent'
4
4
import { ErrorOverlay , overlayId } from './overlay'
5
5
// eslint-disable-next-line node/no-missing-import
@@ -248,7 +248,10 @@ const supportsConstructedSheet = (() => {
248
248
return false
249
249
} ) ( )
250
250
251
- const sheetsMap = new Map ( )
251
+ const sheetsMap = new Map <
252
+ string ,
253
+ HTMLStyleElement | CSSStyleSheet | undefined
254
+ > ( )
252
255
253
256
export function updateStyle ( id : string , content : string ) : void {
254
257
let style = sheetsMap . get ( id )
@@ -260,10 +263,12 @@ export function updateStyle(id: string, content: string): void {
260
263
261
264
if ( ! style ) {
262
265
style = new CSSStyleSheet ( )
266
+ // @ts -expect-error: using experimental API
263
267
style . replaceSync ( content )
264
268
// @ts -expect-error: using experimental API
265
269
document . adoptedStyleSheets = [ ...document . adoptedStyleSheets , style ]
266
270
} else {
271
+ // @ts -expect-error: using experimental API
267
272
style . replaceSync ( content )
268
273
}
269
274
} else {
@@ -308,7 +313,7 @@ async function fetchUpdate({ path, acceptedPath, timestamp }: Update) {
308
313
return
309
314
}
310
315
311
- const moduleMap = new Map ( )
316
+ const moduleMap = new Map < string , ModuleNamespace > ( )
312
317
const isSelfUpdate = path === acceptedPath
313
318
314
319
// make sure we only import each dep once
@@ -338,7 +343,7 @@ async function fetchUpdate({ path, acceptedPath, timestamp }: Update) {
338
343
if ( disposer ) await disposer ( dataMap . get ( dep ) )
339
344
const [ path , query ] = dep . split ( `?` )
340
345
try {
341
- const newMod = await import (
346
+ const newMod : ModuleNamespace = await import (
342
347
/* @vite -ignore */
343
348
base +
344
349
path . slice ( 1 ) +
@@ -375,18 +380,17 @@ interface HotModule {
375
380
interface HotCallback {
376
381
// the dependencies must be fetchable paths
377
382
deps : string [ ]
378
- fn : ( modules : object [ ] ) => void
383
+ fn : ( modules : Array < ModuleNamespace | undefined > ) => void
379
384
}
380
385
386
+ type CustomListenersMap = Map < string , ( ( data : any ) => void ) [ ] >
387
+
381
388
const hotModulesMap = new Map < string , HotModule > ( )
382
389
const disposeMap = new Map < string , ( data : any ) => void | Promise < void > > ( )
383
390
const pruneMap = new Map < string , ( data : any ) => void | Promise < void > > ( )
384
391
const dataMap = new Map < string , any > ( )
385
- const customListenersMap = new Map < string , ( ( data : any ) => void ) [ ] > ( )
386
- const ctxToListenersMap = new Map <
387
- string ,
388
- Map < string , ( ( data : any ) => void ) [ ] >
389
- > ( )
392
+ const customListenersMap : CustomListenersMap = new Map ( )
393
+ const ctxToListenersMap = new Map < string , CustomListenersMap > ( )
390
394
391
395
export function createHotContext ( ownerPath : string ) : ViteHotContext {
392
396
if ( ! dataMap . has ( ownerPath ) ) {
@@ -414,7 +418,7 @@ export function createHotContext(ownerPath: string): ViteHotContext {
414
418
}
415
419
}
416
420
417
- const newListeners = new Map ( )
421
+ const newListeners : CustomListenersMap = new Map ( )
418
422
ctxToListenersMap . set ( ownerPath , newListeners )
419
423
420
424
function acceptDeps ( deps : string [ ] , callback : HotCallback [ 'fn' ] = ( ) => { } ) {
0 commit comments