I have passed an array as prop item and I gave it a type in the interface Props and when I try to give it a default value I get the error line 4 TS2322: Type 'never[ ]'Not assignable to type'(props: readonly<Props>) = >String[]'. Type 'never[]' provides no match for signature '(props: Readonly<Props>): string[]'.
I'm not sure what I'm doing wrong here since this seems to apply to other variables
<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])
P粉4366889312024-03-26 17:16:21
This applies to both the Options API and the Combination API!
const props = withDefaults(defineProps(), { items: () => [] });