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

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

Closed
zhangpaopao0609 opened this issue Sep 21, 2022 · 4 comments
Closed

Comments

@zhangpaopao0609
Copy link

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

@zhangpaopao0609 zhangpaopao0609 changed the title v-model.trim : Incompatible trim() when emit arg is not string v-model.trim: Incompatible trim() when emit arg is not string Sep 21, 2022
@zhangzhonghe
Copy link
Member

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.

@zhangpaopao0609 zhangpaopao0609 changed the title v-model.trim: Incompatible trim() when emit arg is not string Modifier .trim: Incompatible trim() when emit arg is not string Sep 21, 2022
@zhangpaopao0609
Copy link
Author

zhangpaopao0609 commented Sep 21, 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

@sqal
Copy link
Contributor

sqal commented Sep 21, 2022

@zhangpaopao0609 duplicate #5765

@posva
Copy link
Member

posva commented Sep 22, 2022

Duplicate of #5765

@posva posva marked this as a duplicate of #5765 Sep 22, 2022
@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2022
@vuejs vuejs locked and limited conversation to collaborators Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants