-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Vue3 custom element prop type number is a string in production. #8987
Comments
I can't seem to reproduce the problem in the playground |
I reproduced the problem, he only appears in some specific syntax
|
I see what you did. Is it possible to test per these docs: Props Default Values section: https://vuejs.org/guide/typescript/composition-api.html#typing-component-props Thank you |
We really enjoy setting the type with defaults. When using as vue component, typescript provides some valuable suggestions. vue-tsc helps during the type-check command. But when compiling to custom element, it doesn't seem to work. Sum: {{ props.valOne + props.valTwo }} only works correctly if no value is passed to valOne and valTwo. Because the default gets defined correctly (from dist file):
I would almost think that this Thank you again! |
I think this is a bug. The compiler does not compile the type information of the props under the product environment, but the Custom Element does not do special processing in this situation in Runtime cc/@sxzz |
@baiwusanyu-c This is a bug, but your PR won't comletely solve it. when defining a prop like this, without a default: <script setup lang="ts">
const props = defineProps<{
foo: number
}>()
</script>
<template>
<div>{{ foo + bar }}</div>
</template> We end up with this in production: const __sfc__ = _defineComponent({
__name: 'Comp',
props: {
foo: {}
},
setup(__props) { That's a behavior of But when using such a component as a custom element, we get the reported problem, as now the custom element has no way of knowing, at runtime, that it needs to cast this attribute as a number. This likely needs a solution at the compiler level. Either the stripping of props types needs to be removed completely, or it needs to be deactivated when compiling a component as a custom component ( |
You are right, thank you for your help, let me think about how to do it🧐 |
Hey @LinusBorg @baiwusanyu-c , Do you guys think it's worth adding a Number() wrapper around any number value? It would enforce the number conversion. Since the user is clearly defining a number, the enforcement could be helpful. Thanks |
This case of customElement can be specially handled in the compiler, I made some changes in pr, it is not perfect, I don't have time over the weekend, I will improve it next week |
@baiwusanyu-c no worries at all. I saw the PR changes. I was just thinking maybe that could help. Thank you again |
Hello @baiwusanyu-c & @sxzz , Do you guys have any estimates when the new version of vue3 is going to be released? Thank you! |
Hello Vue team. Do you guys have any idea when the fix would be available for this issue (released)? Thank you. |
Hello @LinusBorg , @sxzz , @baiwusanyu-c , I'm still getting the issue after updating "@vitejs/plugin-vue": "^4.5.2". Please let me know if you guys can reproduce. I pushed updated package versions into the repo. Thank you, |
that's because we haven't had a new patch release for Vue since we merged #8989 the changes in the vite plugin are a prerequisite for that. |
|
Vue version
3.3.4
Link to minimal reproduction
https://github.com/SavkaTaras/vue-cue-issues
Steps to reproduce
npm install
npm run build
npm run dev
What is expected?
We import vue component and the same custom element below.
The custom element typeof should be number. The sum of 5.5 + 0.5 should be 6.
What is actually happening?
Custom element typeof returns a string.
Sum is 5.50.5.
System Info
Any additional comments?
Hello vue team,
I hope you are doing well.
@baiwusanyu-c could you please take a look at this issue when you have a moment?
Thank you so much guys,
Taras
The text was updated successfully, but these errors were encountered: