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

Type of generic function as unknown when using tsx component #3309

Closed
s-montigny-desautels opened this issue Jun 19, 2023 · 4 comments
Closed
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@s-montigny-desautels
Copy link
Contributor

Vue version

3.3.4

Description

This issue appears when importing a .tsx component in a .vue component. If the props contain a function with a generic argument, the argument is of type unknown.

Link to minimal reproduction

https://github.com/s-montigny-desautels/vue3.3-issues

Steps to reproduce

$ pnpm install

Look for the error in file BugTSXFunctionUnknown.vue

What is expected?

The type of the function to respect the generic

What is actually happening?

The type of the function argument is of type unknown

Any additional comments?

This issue is only present in a .vue file. When using .tsx file, everything work as expected.

@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 Sep 6, 2023
@rijenkii
Copy link

Smaller reproduction of the seemingly same problem:

<script setup lang="ts">
import { ref } from 'vue';

const val = ref(0);
const test = <K,>(_: { modelValue: K, "onUpdate:modelValue"?: (value: K) => any }) => "";
</script>

<template>
  <test :model-value="123" @update:model-value="val = $event" />
</template>

playground

Error in @update:model-value: Type 'unknown' is not assignable to type 'number'. ts(2322).
When hovering over :model-value and $event their types are shown as unknown.

So, it seems that the problem is not with JSX components, but with all generic functional components.

@rijenkii
Copy link

rijenkii commented Nov 17, 2023

However, bizzarly, type checking in tsx files works without a hitch:

<script lang="tsx">
import { ref } from "vue";

const val = ref(0);
const Test = <K,>(_: { modelValue: K; "onUpdate:modelValue"?: (value: K) => any }) =>
  null;

export default () => (
  <Test modelValue={val.value} onUpdate:modelValue={(event) => (val.value = event)} />
);
</script>

@rijenkii
Copy link

rijenkii commented Nov 17, 2023

Current workaround is using aliases:

<script setup lang="ts">
import { ref } from 'vue';

const val = ref(0);
const test = <K,>(_: { modelValue: K, "onUpdate:modelValue"?: (value: K) => any }) => "";

const testNumber = test<number>;
</script>

<template>
  <testNumber :model-value="123" @update:model-value="val = $event" />
</template>

playground

@s-montigny-desautels
Copy link
Contributor Author

Fixed with Vue 3.4.20

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

3 participants