Skip to content

Conversation

@edison1105
Copy link
Member

@edison1105 edison1105 commented Dec 29, 2025

close #14236

Summary by CodeRabbit

  • Bug Fixes
    • Improved type resolution for properties within global ambient declarations, enabling proper support for indexed access types in declare global blocks.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

The changes add support for resolving indexed access types within global ambient declarations by implementing recursive processing of declare global block contents in the type resolution logic, alongside a corresponding test case validating this functionality.

Changes

Cohort / File(s) Summary
Test coverage for global indexed types
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Adds test case "declare global with indexed access type" verifying that indexed access types on global ambient declarations (e.g., defineProps<Options["code"]>()) correctly resolve to nested properties.
Global block type recording
packages/compiler-sfc/src/script/resolveType.ts
Implements recursive processing of declare global block contents (TSModuleDeclaration with global) to capture type declarations from inner statements and declarations, ensuring global ambient type declarations are properly recorded.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • vuejs/core#13789: Also modifies type recording for declare global blocks in resolveType.ts to ensure inner declarations are captured, using a different approach (unwrapping ExportNamedDeclaration vs. recursive processing).

Suggested labels

ready to merge, scope: sfc, :hammer: p3-minor-bug

Suggested reviewers

  • Doctor-wu
  • LittleSound

Poem

🐰 A global type once lost to the void,
With indexed access left unemployed,
But now we recurse through declarations divine,
Making Options["code"] resolve just fine!
The rabbit rejoices—nested types align! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for handling indexed access types within declare global blocks in the compiler.
Linked Issues check ✅ Passed The PR successfully addresses issue #14236 by implementing special handling for types declared within declare global blocks, enabling indexed access type resolution.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing indexed access type handling in declare global blocks as specified in issue #14236.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edison/fix/14236

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 103 kB 39.1 kB 35.2 kB
vue.global.prod.js 161 kB 59.1 kB 52.6 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47 kB 18.4 kB 16.8 kB
createApp 55.2 kB 21.4 kB 19.6 kB
createSSRApp 59.4 kB 23.2 kB 21.1 kB
defineCustomElement 60.7 kB 23.1 kB 21.1 kB
overall 69.5 kB 26.7 kB 24.3 kB

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 29, 2025

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14260
npm i https://pkg.pr.new/@vue/compiler-core@14260
yarn add https://pkg.pr.new/@vue/compiler-core@14260.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14260
npm i https://pkg.pr.new/@vue/compiler-dom@14260
yarn add https://pkg.pr.new/@vue/compiler-dom@14260.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14260
npm i https://pkg.pr.new/@vue/compiler-sfc@14260
yarn add https://pkg.pr.new/@vue/compiler-sfc@14260.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14260
npm i https://pkg.pr.new/@vue/compiler-ssr@14260
yarn add https://pkg.pr.new/@vue/compiler-ssr@14260.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14260
npm i https://pkg.pr.new/@vue/reactivity@14260
yarn add https://pkg.pr.new/@vue/reactivity@14260.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14260
npm i https://pkg.pr.new/@vue/runtime-core@14260
yarn add https://pkg.pr.new/@vue/runtime-core@14260.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14260
npm i https://pkg.pr.new/@vue/runtime-dom@14260
yarn add https://pkg.pr.new/@vue/runtime-dom@14260.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14260
npm i https://pkg.pr.new/@vue/server-renderer@14260
yarn add https://pkg.pr.new/@vue/server-renderer@14260.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14260
npm i https://pkg.pr.new/@vue/shared@14260
yarn add https://pkg.pr.new/@vue/shared@14260.tgz

vue

pnpm add https://pkg.pr.new/vue@14260
npm i https://pkg.pr.new/vue@14260
yarn add https://pkg.pr.new/vue@14260.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14260
npm i https://pkg.pr.new/@vue/compat@14260
yarn add https://pkg.pr.new/@vue/compat@14260.tgz

commit: 6ebeb22

@edison1105 edison1105 added scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Dec 29, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)

1470-1488: Test validates the fix, but consider enhancing coverage.

The test correctly validates that indexed access types work with global declarations. It should pass with the implementation changes in resolveType.ts.

However, issue #14236 specifically mentions Record<string, unknown> within global indexed types causing errors. Consider adding a test case that includes this pattern for more comprehensive validation:

Optional: Enhanced test case with Record
test('declare global with indexed access type and Record', () => {
  const files = {
    '/global.d.ts': `
      declare global {
        type Options = {
          code: {
            selected: boolean
            metadata: Record<string, unknown>
          }
        }
      }`,
  }
  const { props } = resolve(`defineProps<Options["code"]>()`, files, {
    globalTypeFiles: Object.keys(files),
  })

  expect(props).toStrictEqual({
    selected: ['Boolean'],
    metadata: ['Object'],
  })
})
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aac7e18 and 6ebeb22.

📒 Files selected for processing (2)
  • packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
  • packages/compiler-sfc/src/script/resolveType.ts
🔇 Additional comments (1)
packages/compiler-sfc/src/script/resolveType.ts (1)

1391-1402: Well-structured fix for global block type recording.

The implementation correctly handles declare global blocks by recursively processing their contents and recording type declarations. The special handling for ExportNamedDeclaration at lines 1395-1396 ensures exported types within global blocks are captured, while the else branch handles regular declarations. The short-circuit break at line 1401 appropriately prevents normal module declaration processing.

This change enables indexed access types on global declarations (e.g., Options["code"]) to resolve correctly, addressing issue #14236.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plugin:vite:vue] [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type

2 participants