Subscribe on changes!

Modifier `.trim`: Incompatible `trim()` when emit arg is not string

avatar
Sep 21st 2022

Vue version

3.2.39

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-qujitj?file=src/App.vue

Steps to reproduce

  1. Open the console
  2. Enter any value in the second input box
  3. Corresponding error occurs image

What is expected?

  1. Trigger the emit function normally,
  2. If the arg value is incompatible with trim(), print a warning on the console

What is actually happening?

Uncaught TypeError: a.trim is not a function

image

System Info

No response

Any additional comments?

trim modifier implementation

image
avatar
Sep 21st 2022

I think you should change $emit('update:modelValue', $event.target.value, {}) to $emit('update:modelValue', $event.target.value), because in this scenario the third parameter is completely redundant.

A warning should be triggered when the user sets a redundant parameter, while the redundant parameter can simply be ignored.

avatar
Sep 21st 2022

I think you should change $emit('update:modelValue', $event.target.value, {}) to $emit('update:modelValue', $event.target.value), because in this scenario the third parameter is completely redundant.

A warning should be triggered when the user sets a redundant parameter, while the redundant parameter can simply be ignored.

Thanks.

Yes, it is redundant in here, but what I really want to express is:

If the parameter type is not string, an error will directly cause the program to crash. Moreover, although only one parameter is required in a controlled scenario, the emit function supports multiple parameters.

so in my opinion, it should take into account the situation where the user uses modifiers .trim and passes multiple parameters of different types

I think there are two ways:

  • Inform the user that there are redundant parameters and only process the first parameter, I feel that this is not very good
  • Make the corresponding return according to the type of the parameter,trim() of string type, other direct return, better i think
avatar
Sep 21st 2022

@zhangpaopao0609 duplicate https://github.com/vuejs/core/issues/5765