Skip to content

Types of generic parameters in components defined with defineComponent are always unknown #3745

Closed
@rijenkii

Description

@rijenkii

Playground reproduction

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood reproduction ✨This issue provides a good reproduction, we will be able to investigate it first

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions