Closed
Description
I have defined the same component using <script setup>
and defineComponent
:
// CompSetup.vue
<script setup lang="ts" generic="T">
defineProps<{ msg: T; list: T[] }>();
</script>
// CompDefine.vue
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent(<T>(_: { msg: T; list: T[] }) => () => null);
</script>
When using them, CompSetup
automatically infers the types of arguments, however CompDefine
does not:
<template>
<CompSetup :msg="123" :list="['123']" />
<!-- Displays an error saying that `'string' is not assignable to 'number'` -->
<CompDefine :msg="123" :list="['123']" />
<!-- Displays no errors, when hovering over `:msg` and `:list` displays types `unknown` and `unknown[]` respectively -->
</template>