`checkRequiredFallthroughAttributes` 会排除从具有设置的 props 的子组件继承的属性

作者: GrantGryczan创建于 2026年6月11日更新于 2026年6月11日
标签pending triage

vue-tsc -b --noEmit App.vue:6:11 - error TS2353: Object literal may only specify known properties, and 'optional' does not exist in type '{ readonly style?: unknown; readonly key?: PropertyKey | undefined; readonly ref?: VNodeRef | undefined; readonly class?: unknown; readonly ref_for?: boolean | undefined; ... 6 more ...; readonly onVnodeUnmounted?: VNodeMountHook | ... 1 more ... | undefined; } & VNodeProps & AllowedComponentProps & ComponentCustomP...'. 6 ~~~~~~~~ App.vue:7:11 - error TS2353: Object literal may only specify known properties, and 'required' does not exist in type '{ readonly style?: unknown; readonly key?: PropertyKey | undefined; readonly ref?: VNodeRef | undefined; readonly class?: unknown; readonly ref_for?: boolean | undefined; ... 6 more ...; readonly onVnodeUnmounted?: VNodeMountHook | ... 1 more ... | undefined; } & VNodeProps & AllowedComponentProps & ComponentCustomP...'. 7 ~~~~~~~~ Found 2 errors. 链接到最小重现 https://GitHub.com/GrantGryczan/vue-language-tools-issue 任何其他评论? 这与 #6082 相同,但在启用 checkRequiredFallthroughAttributes 时仍会出现此问题。在 #6088 中进行了相关讨论。总结来说, @KazariEX 对解决此问题的修复做了以下评论: 如果它变成可选的,并且同时明确定义了同名的属性,则两个属性类型将合并为一个联合。此行为在 https://GitHub.com/vuejs/language-tools/issues/5882#issuecomment-4464054704 中提到了。 这是当前代码生成与 TS 怪癖相冲突的结果。当然,如果能避免它,就太好了,但这样做可能会引入更复杂的代码生成逻辑和潜在的 TS 性能问题,因此我选择绕过它。 如果您仍然需要这些属性可以外部覆盖,则可以明确定义它们。 我回复: 您是否不能使用 Omit<X, keyof Y> & Y,其中 X 是继承的属性,而 Y 是明确的属性?这样,具有相同名称的属性就不会合并。我不熟悉实现。但至少,我怀疑非指数性能下降并不是一个巨大的问题,因为这是一个可选功能,而且性能已经是在 …

内容来源: vuejs/language-tools