Repository navigation
fix(compiler-sfc): enhance inferRuntimeType to support TSMappedType with indexed access - #13848
Conversation
…ith indexed access
only for the strict pattern {[K in keyof T]: T[K]}
close #13847
WalkthroughAdds support in inferRuntimeType for a specific TypeScript mapped-type pattern that uses indexed access and keyof constraints, and adds tests verifying resolution of a mapped type with indexed access in defineProps. Tests were added twice (duplicated). 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 mapped pattern (K in keyof T => T[K])
alt pattern & refs match
MT->>RT: retrieve target type from typeParameters
RT-->>SFC: inferred runtime type (from target)
else pattern mismatch
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 Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
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.
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/Placementin 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
filesmap used elsewhere in this suite.packages/compiler-sfc/src/script/resolveType.ts (2)
1819-1819: PreserveisKeyOfwhen delegating to the target type.If
TSMappedTypeappears under akeyofoperator, the current call drops theisKeyOfcontext, 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.
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
only for the strict pattern
{[K in keyof T]: T[K]}close #13847
Summary by CodeRabbit