我已經(jīng)傳遞了一個(gè)陣列作為道具項(xiàng),我在介面Props 中給了它一個(gè)類型,當(dāng)我嘗試給它一個(gè)預(yù)設(shè)值時(shí),我收到錯(cuò)誤第四行TS2322:類型'never[ ]'不可指派給型別'(道具:唯讀<Props>)= >字串[]'。類型“never[]”不提供與簽名“(props: Readonly<Props>): string[]”的匹配項(xiàng)。
我不確定我在這裡做錯(cuò)了什麼,因?yàn)檫@似乎適用於其他變數(shù)
<script setup lang="ts"> import {ref} from "vue"; interface Props { items?: Array<string> } const props = withDefaults(defineProps<Props>(), { items: [] }); let selectedItem = ref(props.items[0])