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

Passing any prop to generic component makes other props not required (defineModel) #4972

Open
DrWarpMan opened this issue Oct 31, 2024 · 1 comment · May be fixed by #4983
Open

Passing any prop to generic component makes other props not required (defineModel) #4972

DrWarpMan opened this issue Oct 31, 2024 · 1 comment · May be fixed by #4983
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔨 p3-minor-bug

Comments

@DrWarpMan
Copy link

DrWarpMan commented Oct 31, 2024

Vue - Official extension or vue-tsc version

2.1.10

VSCode version

1.94.2

Vue version

3.5.12

TypeScript version

5.6.3

System Info

No response

package.json dependencies

No response

Steps to reproduce

The bugs are 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');

/* BUG 1 - moved to: https://github.com/vuejs/core/issues/12307 */

// 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>

  <!-- BUG 2 -->
   
  <Comp/> <!-- this errors as expected, cause modelValue prop is not provided -->
  <Comp :whatever="''" /> <!-- this does not error, somehow passing *any* prop makes the model value not required? -->
  
</template>

Comp.vue

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

<template />

What is expected?

Bug 1: Render functions should have proper type based on the provided value to the generic component.
Moved to: vuejs/core#12307

Bug 2: Passing any/non-existing prop to a generic component should not make the component's model value "not required".

What is actually happening?

Bug 1: Render functions have 'unknown' type, regardless of the provided value to the generic component.
Moved to: vuejs/core#12307

Bug 2: Passing any/non-existing prop to a generic component makes the component's model value "not required".

Link to minimal reproduction

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

Any additional comments?

Possibly related to PR: #4823 (Issue: #4822)

@KazariEX
Copy link
Collaborator

KazariEX commented Nov 1, 2024

For bug 1, please open a new issue at https://github.com/vuejs/core. We should compile generic components into functional components, but in reality it hasn't done so.

@KazariEX KazariEX added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first upstream: core and removed pending triage labels Nov 1, 2024
@DrWarpMan DrWarpMan changed the title Broken types when using render functions with generic components & defineModel Passing any prop to generic component makes other props not required (defineModel) Nov 1, 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 🔨 p3-minor-bug
Projects
None yet
2 participants