Quellcode durchsuchen

fix(types): add fallback stub for DOM types when DOM lib is absent (#11598)

Tycho vor 1 Jahr
Ursprung
Commit
fee669764f
1 geänderte Dateien mit 9 neuen und 1 gelöschten Zeilen
  1. 9 1
      packages/runtime-dom/src/index.ts

+ 9 - 1
packages/runtime-dom/src/index.ts

@@ -33,9 +33,17 @@ import type { vShow } from './directives/vShow'
 import type { VOnDirective } from './directives/vOn'
 import type { VModelDirective } from './directives/vModel'
 
+/**
+ * This is a stub implementation to prevent the need to use dom types.
+ *
+ * To enable proper types, add `"dom"` to `"lib"` in your `tsconfig.json`.
+ */
+type DomStub = {}
+type DomType<T> = typeof globalThis extends { window: unknown } ? T : DomStub
+
 declare module '@vue/reactivity' {
   export interface RefUnwrapBailTypes {
-    runtimeDOMBailTypes: Node | Window
+    runtimeDOMBailTypes: DomType<Node | Window>
   }
 }