Skip to content

fix(compiler-sfc): use correct scope when resolving indexed access types from external files#14297

Merged
edison1105 merged 2 commits intomainfrom
edison/fix/14292_
Jan 19, 2026
Merged

fix(compiler-sfc): use correct scope when resolving indexed access types from external files#14297
edison1105 merged 2 commits intomainfrom
edison/fix/14292_

Conversation

@edison1105
Copy link
Member

@edison1105 edison1105 commented Jan 8, 2026

close #14292

Summary by CodeRabbit

  • Bug Fixes

    • Improved runtime type inference for complex relative-imported types (indexed-access and extends scenarios), reducing incorrect inference when base types are unresolved.
  • Tests

    • Added tests covering relative imports with indexed access types and extends-resolution edge cases to prevent regressions.
  • Chores

    • Minor public type/signature adjustments to support the new inference behavior.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

Adds two tests for resolving indexed-access/imported types and updates type-resolution logic to honor per-type owner scopes and a new silentOnExtendsFailure context flag; runtime inference temporarily silences extends failures during inference. No public API removals, only signature extensions.

Changes

Cohort / File(s) Summary
Type resolution core
packages/compiler-sfc/src/script/resolveType.ts
- Added silentOnExtendsFailure?: boolean to TypeResolveContext and included warn in SimpleTypeResolveContext pick list.
- When resolving interfaces, silence extends resolution errors if ctx.silentOnExtendsFailure is true.
- inferRuntimeType sets ctx.silentOnExtendsFailure = true during runtime inference (restored after).
- flattenTypes and resolve paths now prefer each type's `(types[i] as MaybeWithScope)._ownerScope
Tests
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Added two tests: "relative import with indexed access type" and "relative import with indexed access type with unresolvable extends" to verify runtime prop inference (['Boolean','String','Unknown']) and dependency collection for indexed-access types imported from local files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • LittleSound
  • Doctor-wu
  • sxzz

Poem

🐰 I hopped through scopes both near and far,
Found owners hidden like a star.
I nudged a flag to hush a fright,
Now indexed types infer just right. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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: fixing scope resolution for indexed access types from external files, which directly addresses the core issue.
Linked Issues check ✅ Passed The PR implementation correctly addresses issue #14292 by using owner scopes for type resolution and silently handling extends failures during runtime inference.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing indexed access type resolution from external files; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18c4b54 and 3ce8aeb.

📒 Files selected for processing (2)
  • packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
  • packages/compiler-sfc/src/script/resolveType.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-sfc/src/script/resolveType.ts (1)
packages/compiler-sfc/src/script/context.ts (1)
  • ScriptCompileContext (14-151)
🔇 Additional comments (8)
packages/compiler-sfc/src/script/resolveType.ts (6)

77-77: LGTM: Adding 'warn' method to SimpleTypeResolveContext.

This addition ensures SimpleTypeResolveContext remains compatible with operations that may use the warning mechanism during type resolution.


99-104: LGTM: Extending TypeResolveContext with silentOnExtendsFailure flag.

The optional flag provides fine-grained control over error handling during extends resolution, enabling runtime type inference to proceed even when base types cannot be fully resolved.


437-452: Solid error handling with helpful guidance.

The conditional error handling allows runtime type inference to proceed when extends resolution fails (by silencing the error), while still providing clear, actionable error messages with @vue-ignore workaround guidance when silentOnExtendsFailure is false.


1533-1535: Well-structured flag management with proper cleanup.

The try-finally pattern correctly saves and restores the silentOnExtendsFailure flag, ensuring runtime type inference operates in a silenced-error context without leaking state to callers. The finally block guarantees cleanup even when inference fails.

Also applies to: 1904-1906


1917-1924: Core fix: Using per-type owner scope for single-type inference.

This change ensures that when inferring runtime types for a single type, the type's own _ownerScope is used if available, rather than always using the provided scope. This is essential for correctly resolving indexed access types that originate from external files, addressing the root cause reported in #14292.


1926-1940: Consistent scope propagation for multi-type inference.

The multi-type path correctly applies the same owner-scope logic, ensuring each type in a union/intersection is inferred using its own _ownerScope. This maintains consistency with the single-type fix and ensures correct behavior across all type compositions.

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (2)

1139-1162: Excellent test coverage for basic indexed access type resolution.

This test validates the core fix by verifying that indexed access types from external files (InputHTMLAttributes['required']) are correctly resolved with their proper scope, resulting in accurate runtime type inference. The test also confirms dependency tracking is working as expected.


1164-1195: Critical test for silentOnExtendsFailure behavior.

This test exercises a more complex scenario where the indexed access type comes from an interface with unresolvable extends (referencing undefined ClipboardEvent). It validates that runtime type inference proceeds successfully by silently ignoring the extends resolution failure while still correctly inferring the required property type. This ensures the fix handles real-world cases where external dependencies may be incomplete.


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

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

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 Jan 8, 2026

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 3ce8aeb

@edison1105 edison1105 marked this pull request as draft January 8, 2026 02:20
@edison1105 edison1105 marked this pull request as ready for review January 8, 2026 03:31
@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Jan 8, 2026
@edison1105 edison1105 merged commit f0f0a21 into main Jan 19, 2026
16 checks passed
@edison1105 edison1105 deleted the edison/fix/14292_ branch January 19, 2026 00:42
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. ready to merge The PR is ready to be merged. scope: sfc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type based boolen prop declaration compiles to JS string when use imported TS type

1 participant