英文:
After update of Vue 3 withDefaults throws a TypeScript error
问题
I'm providing the translation for the text you provided:
我试图更新 Vue 3 的版本(从 3.2.x
到 3.3.x
)。
但出现了一个问题,当我使用 withDefaults
时会出现错误:
错误消息是:
> 参数类型 DefineProps<Props, BooleanKey<Props>>
无法赋值给参数类型 DefineProps<Readonly<Props> & {}, keyof Readonly<Props> & {}>
我猜我是按照文档中描述的方式做的,问题出在哪里?
更新:看起来这个问题只会发生在非布尔字段上:
// 这个可以工作
withDefaults(defineProps<{readonly foo: boolean}>(), { foo: true });
// 这个不工作
withDefaults(defineProps<{readonly foo: string}>(), { foo: 'foo' });
英文:
I'm trying to update version of Vue 3 (3.2.x
-> 3.3.x
).
But for some reason I have an error when using withDefaults
:
<script setup lang="ts">
interface Props {
readonly title: string;
}
// THIS WORKS
const props = defineProps<Props>();
// THIS DOESN'T WORK (guess because of withDefaults)
const props = withDefaults(defineProps<Props>(), { title: '' });
...
</script>
The error message is:
>Argument type DefineProps<Props, BooleanKey<Props>>
is not assignable to parameter type DefineProps<Readonly<Props> & {}, keyof Readonly<Props> & {}>
I guess I'm doing this exactly how it's described in docs, what's the problem here?
Update: Looks like this issue happens only for non-boolean fields:
// THIS WORKS
withDefaults(defineProps<{readonly foo: boolean}>(), { foo: true });
// THIS DOESN'T WORK
withDefaults(defineProps<{readonly foo: string}>(), { foo: 'foo' });
答案1
得分: 5
这是IDE的错误,已在WEB-61241上进行跟踪;请关注它以获取更新。
作为一种临时解决方法,您可以尝试下载WebStorm 2023.2 EAP,并在首选项 | 语言和框架 | TypeScript | Vue中启用Volar支持。
英文:
This is the IDE bug, tracked at WEB-61241; please follow it for updates
as a workaround, you can try downloading the WebStorm 2023.2 EAP and enabling Volar support in Preferences | Languages & Frameworks | TypeScript | Vue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论