The import boolean type is correct, but the template props parsing is incorrect
Vue version
3.3.12
Link to minimal reproduction
Steps to reproduce
<script setup lang="ts">
import type { UploadProps } from 'naive-ui';
interface PropsType extends /** @vue-ignore */ UploadProps {
// Class
class?: string | string[];
// Loading
loading?: boolean;
buttonName?: string;
directoryDnd?: UploadProps['directoryDnd'];
max?: UploadProps['max'];
listType?: UploadProps['listType'];
}
const props = withDefaults(defineProps<PropsType>(), {
class: undefined,
loading: false,
buttonName: undefined,
directoryDnd: false,
max: 1,
listType: undefined
});
</script>
<template>
<n-upload :class="props.class" :max="max" :list-type="listType">
{{ props }}
</n-upload>
</template>
What is expected?
Parsing props boolean type correctly
What is actually happening?
With UploadProps['directoryDnd'], the ts type prompt is correct, but the props are resolved as strings
System Info
windows
chrome
Any additional comments?
No response
@RicardoErii
https://github.com/jahnli/test1
运行后只需要关注
src\views\login\login.vue
src\components\base-ui\base-upload\base-upload.vue
This is expected behavior because you are using the @vue-ignore
comment, which means the Vue compiler will not try to resolve the actual types of UploadProps
and just assume these props have no specified types at runtime.
Unfortunately currently there is no proper fix for this because the UploadProps
from naive-ui
is too complex. The workaround is to explicitly declare directoryDnd
with boolean
type.
But we are not sure which types can be parsed at present. Currently, boolean
cannot be parsed, but number
can. If @vue-ignore
is not used, external props cannot be imported.
@yyx990803
使用https://github.com/so1ve/vue.ts/tree/main/packages/complex-types。
Thank you for your suggestion. I would like to ask, is this package suitable for production environment?