Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rijenkii opened this issue Nov 21, 2023 · 4 comments
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@rijenkii
Copy link

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>
@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Nov 21, 2023
@s-montigny-desautels
Copy link
Contributor

Should be fixed with Vue 3.4.20.

@so1ve so1ve closed this as completed Feb 27, 2024
@so1ve so1ve added upstream and removed bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Feb 27, 2024
@rijenkii
Copy link
Author

rijenkii commented Feb 27, 2024

This is not really fixed: Playground

<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 `number` and `string[]` respectively -->
</template>

So, unknown is not shown, but fields are still not linked together.
Maybe this should actually be tracked in #3782.

@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed upstream labels Feb 27, 2024
@so1ve
Copy link
Member

so1ve commented Feb 27, 2024

This looks like a bug in volar. I'll reopen this issue.

@so1ve so1ve reopened this Feb 27, 2024
@KermanX
Copy link
Collaborator

KermanX commented Aug 14, 2024

This seems to have been fixed in the latest version.

@KermanX KermanX closed this as completed Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

4 participants