Skip to content

Generic vue types break depending how props are accessed in template. #3714

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

Closed
minht11 opened this issue Nov 6, 2023 · 2 comments
Closed
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first upstream

Comments

@minht11
Copy link

minht11 commented Nov 6, 2023

Generic vue types break depending how props are accessed in template.
Lets take component like this, it all works fine:

<script lang="ts">
export const customFormatter = (num: number) => `${num * 3}!!!`
export type FormatNumber<T> = (num: T) => string;
</script>

<script lang="ts" setup generic="T extends number, Formatter extends FormatNumber<T>">
const props = defineProps<{
	value: T,
	formatter: Formatter
}>()
</script>

<template>
	{{ value }} {{ props.formatter(props.value) }}
</template>

Now take the same component and instead use prop directy inside template without props. like this:

<script lang="ts">
export const customFormatter = (num: number) => `${num * 3}!!!`
export type FormatNumber<T> = (num: T) => string;
</script>

<script lang="ts" setup generic="T extends number, Formatter extends FormatNumber<T>">
defineProps<{
	value: T,
	formatter: Formatter
}>()
</script>

<template>
	{{ value }} {{ formatter(value) }}
</template>

And you will get This expression is not callable. Type 'unknown' has no call signatures.
Screenshot 2023-11-07 at 00 54 05

@so1ve
Copy link
Member

so1ve commented Nov 7, 2023

Related #3651 vuejs/core#9418

@so1ve so1ve added upstream good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Nov 7, 2023
@KazariEX
Copy link
Member

KazariEX commented Sep 26, 2024

It works well with the latest version. If it still happens, feel free to open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first upstream
Projects
None yet
Development

No branches or pull requests

3 participants