With Vue 3 (composition api) + Typescript , I am trying to set default values on the props after defining them with an interface.
I get a typescript error when I try to set default value [] on one of the props. How can I set a default empty array?
<script setup lang="ts">
interface IProps {
title: string;
things: any[];
productUrl: any;
}
const props = withDefaults(defineProps<IProps>(), {
title: "",
things: [], //<-- error (se below)
productUrl: "",
});
The error:
Type 'never[]' is not assignable to type '(props: Readonly<IProps>) => any[]'.
It also says:
The expected type comes from property 'things' which is declared here on type
'InferDefaults<Readonly<IProps>>'