You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The withDefaults function loses arguments when assigning a function default value #5253
But indeed, a method with this: undefined doesn't work work on withDefaults(). But it does with arrow functions. Not sure if this is a necessary consequence of the TS limitation mentioned in the docs or we can fix it.
The function-parameter generation bug was fixed by #12823 (b0a1f05). Rechecked the original method default and the variants from the comments, including the this: undefined annotations, with Vue 3.5.43 (4ab865a): all six compiled callbacks retain their argument and return TEST for test. The method variants lose their argument in the Vue 3.2.26 control. The declarations also pass TypeScript 5.6.3 and 6.0.3, while an invalid numeric argument is still rejected.
The original Playground also places const msg = ref('') outside <script setup>; that declaration needs to be inside the script block to run the template. This is separate from the compiler bug above. Closing as the reported parameter-loss issue is fixed.
Activity
jacekkarczmarczyk commentedon Jan 13, 2022
Arrow function seems to work
hcg1023 commentedon Jan 13, 2022
jacekkarczmarczyk commentedon Jan 13, 2022
example
hcg1023 commentedon Jan 13, 2022
Thank you, but why doesn't my way of writing it work? I think it's still a bug
LinusBorg commentedon Jan 13, 2022
When using a method like you do, you would have to explicitly type
this: undefinedas the first argument of the method.hcg1023 commentedon Jan 14, 2022
I specified this: undefined as you said, but it still does not work properly. I have tried three ways of writing, maybe you need to teach me
sfc.vuejs.org
LinusBorg commentedon Jan 14, 2022
The mentioned fact that you need to use an arrow function or annotate
thisproperly is documented here:https://v3.vuejs.org/guide/typescript-support.html#annotating-props
But indeed, a method with
this: undefineddoesn't work work onwithDefaults(). But it does with arrow functions. Not sure if this is a necessary consequence of the TS limitation mentioned in the docs or we can fix it.fix: The withDefaults function loses arguments when assigning a funct…
hcg1023 commentedon Mar 23, 2022
I created a PR for this problem #5615
fix(compiler-sfc): fix The withDefaults function loses arguments when…
edison1105 commentedon Sep 19, 2026
The function-parameter generation bug was fixed by #12823 (b0a1f05). Rechecked the original method default and the variants from the comments, including the
this: undefinedannotations, with Vue 3.5.43 (4ab865a): all six compiled callbacks retain their argument and returnTESTfortest. The method variants lose their argument in the Vue 3.2.26 control. The declarations also pass TypeScript 5.6.3 and 6.0.3, while an invalid numeric argument is still rejected.The original Playground also places
const msg = ref('')outside<script setup>; that declaration needs to be inside the script block to run the template. This is separate from the compiler bug above. Closing as the reported parameter-loss issue is fixed.