-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-sfc): enhance inferRuntimeType to support TSMappedType with indexed access #13848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ith indexed access only for the strict pattern {[K in keyof T]: T[K]} close #13847
WalkthroughAdds runtime type inference for a specific TS mapped type pattern in inferRuntimeType and introduces tests validating mapped type with indexed access resolution in defineProps. No public API changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as SFC Type Annotations
participant SFC as compiler-sfc
participant RT as inferRuntimeType
participant MT as TSMappedType Branch
Dev->>SFC: defineProps<{ placement?: Placement }>()
SFC->>RT: inferRuntimeType(node, typeParameters)
alt Node is TSMappedType
RT->>MT: Validate pattern ({ [K in keyof T]: T[K] })
alt Pattern and references match
MT-->>RT: Resolve target from typeParameters
RT-->>SFC: Inferred runtime type
else Unsupported/invalid pattern
MT-->>RT: UNKNOWN_TYPE
RT-->>SFC: UNKNOWN_TYPE
end
else Other node kinds
RT-->>SFC: Existing inference paths
end
SFC-->>Dev: Prop runtime type(s) for validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes[No out-of-scope functional code changes detected.] Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this 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 (3)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)
734-748
: Good regression coverage; add an import-based case mirroring #13847.This validates the mapped-identity path via inline types. To guard against future regressions that involve imported aliases (the original failure mode), add a companion test that defines
Prettify
/Placement
in an external file and imports it in the SFC before callingdefineProps
. This ensures cross-file resolution and caching paths participate in the fix.I can draft the import-based test using the local
files
map used elsewhere in this suite.packages/compiler-sfc/src/script/resolveType.ts (2)
1819-1819
: PreserveisKeyOf
when delegating to the target type.If
TSMappedType
appears under akeyof
operator, the current call drops theisKeyOf
context, which can change the inferred runtime type. Propagate the flag.- return inferRuntimeType(ctx, targetType, scope) + return inferRuntimeType(ctx, targetType, scope, isKeyOf)
1784-1824
: Optional: accept trivially-equivalent variants.If you want slightly broader compatibility without losing the “strict pattern” intent, consider also accepting readonly/optional modifiers that don’t affect value inference (e.g.,
{ readonly [K in keyof T]-?: T[K] }
). This would remain conservative, but reduce surprises from common utility aliases.I can follow up with a tiny helper (e.g.,
isIdentityMappedType(node)
) and a couple of focused tests if desired.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
(1 hunks)packages/compiler-sfc/src/script/resolveType.ts
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-sfc/src/script/resolveType.ts (1)
packages/compiler-sfc/src/script/utils.ts (1)
UNKNOWN_TYPE
(13-13)
🔇 Additional comments (1)
packages/compiler-sfc/src/script/resolveType.ts (1)
1784-1824
: Mapped-identity recognition LGTM for{ [K in keyof T]: T[K] }
.The structural checks are tight and limited to the declared scope; this should correctly restore string inference for
Prettify<T>
without widening unrelated mapped types.
only for the strict pattern
{[K in keyof T]: T[K]}
close #13847
Summary by CodeRabbit