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

Broken types when using render functions with generic components & defineModel #12307

Open
DrWarpMan opened this issue Nov 1, 2024 · 4 comments
Labels
need documentation Not necessarily a bug, but proper documentation is needed scope: types

Comments

@DrWarpMan
Copy link

DrWarpMan commented Nov 1, 2024

Vue version

3.5.12

Link to minimal reproduction

https://github.com/DrWarpMan/vue-generic-bug

Steps to reproduce

The bug is described in the comments of the code.

App.vue

<script setup lang="ts">
import { h, ref } from 'vue';
import Comp from './Comp.vue';

const foo = ref<string>('foo');

// val should be of type 'string', not 'unknown'
const FunctionalComponent = () => h(Comp, {
  /* unknown */ modelValue: foo.value, 
  ['onUpdate:modelValue']: (val /* unknown */) => foo.value = val,
});
</script>

<template />

Comp.vue

<script setup lang="ts" generic="T">
defineModel<T>({required: true});
</script>

<template />

What is expected?

Render functions should have proper type based on the provided value to the generic component.

What is actually happening?

Render functions have 'unknown' type, regardless of the provided value to the generic component.

System Info

No response

Any additional comments?

Issue was moved from language-tools repo.

@edison1105
Copy link
Member

should be

const FunctionalComponent = () => h(Comp<string>, {
  modelValue: foo.value, 
  ['onUpdate:modelValue']: (val) => foo.value = val,
});

@DrWarpMan
Copy link
Author

So you have to manually specify it, it can't get inferred?

@edison1105
Copy link
Member

For generic components, you need to specify the type; there is no way to infer it automatically.

@DrWarpMan
Copy link
Author

Okay, now that I see it, it seems pretty straightforward, but I wonder if this should be mentioned somewhere in the docs?

In any case, the issue can be closed.

@edison1105 edison1105 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
@edison1105 edison1105 reopened this Nov 1, 2024
@edison1105 edison1105 added the need documentation Not necessarily a bug, but proper documentation is needed label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need documentation Not necessarily a bug, but proper documentation is needed scope: types
Projects
None yet
Development

No branches or pull requests

2 participants