]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): handle indexed access types in declare global blocks (#14260)
authoredison <daiwei521@126.com>
Mon, 19 Jan 2026 00:47:11 +0000 (08:47 +0800)
committerGitHub <noreply@github.com>
Mon, 19 Jan 2026 00:47:11 +0000 (08:47 +0800)
close #14236

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
packages/compiler-sfc/src/script/resolveType.ts

index 4587d1c820e9d7dd6bdc088debd10125d20afed4..a24a21c23cb66367855a7afcfab73486ae00eb7d 100644 (file)
@@ -1525,6 +1525,26 @@ describe('resolveType', () => {
       })
     })
 
+    test('declare global with indexed access type', () => {
+      const files = {
+        '/global.d.ts': `
+          declare global {
+            type Options = {
+              code: {
+                selected: boolean
+              }
+            }
+          }`,
+      }
+      const { props } = resolve(`defineProps<Options["code"]>()`, files, {
+        globalTypeFiles: Object.keys(files),
+      })
+
+      expect(props).toStrictEqual({
+        selected: ['Boolean'],
+      })
+    })
+
     // #9871
     test('shared generics with different args', () => {
       const files = {
index 1cd4c0853609812f4f4bd3eb72535bff38b0e672..393fd1a4e4189a8a4b5cd10556141ba75a251c3e 100644 (file)
@@ -1399,6 +1399,18 @@ function recordType(
     case 'TSInterfaceDeclaration':
     case 'TSEnumDeclaration':
     case 'TSModuleDeclaration': {
+      // Handle `declare global { ... }` blocks by recursively processing their contents
+      if (node.type === 'TSModuleDeclaration' && node.global) {
+        const body = node.body as TSModuleBlock
+        for (const s of body.body) {
+          if (s.type === 'ExportNamedDeclaration' && s.declaration) {
+            recordType(s.declaration, types, declares)
+          } else {
+            recordType(s, types, declares)
+          }
+        }
+        break
+      }
       const id = overwriteId || getId(node.id)
       let existing = types[id]
       if (existing) {