Subscribe on changes!

The import boolean type is correct, but the template props parsing is incorrect

avatar
Jan 10th 2024

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>

01b1803002696086092c3cf666fcbb0

image

9554822b6217119dd4f22ea1d44cca6

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

avatar
Jan 10th 2024

请提供一个最小可复现问题的仓库链接,就图片来看不能确定到底是谁的问题

avatar
Jan 10th 2024

@RicardoErii

https://github.com/jahnli/test1

运行后只需要关注

src\views\login\login.vue src\components\base-ui\base-upload\base-upload.vue

avatar
Jan 11th 2024

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.

avatar
Jan 11th 2024

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

avatar
Jan 11th 2024

But I found that if I remove @vue-ignore, the parsing is still wrong

avatar
Jan 11th 2024

使用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?

avatar
Jan 11th 2024

Still experimental, but it should resolve your problem. If you find any bug plz report it :)

avatar
Jan 11th 2024

It only affects props that have special runtime casting behavior (mostly boolean).

avatar
Jan 11th 2024

Ok, thank you

avatar
Jan 11th 2024

@so1ve Do you still need to specify @vue-ignore after using complex-types?

avatar
Jan 11th 2024

No