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

"TypeError: Cannot use 'in' operator to search for 'names' in bf7823uhvbon3f289ph32f #7381

Closed
lopugit opened this issue Jan 4, 2018 · 9 comments

Comments

@lopugit
Copy link

lopugit commented Jan 4, 2018

Version

2.5.13

Reproduction link

https://jsfiddle.net/49gptnad/905/

Steps to reproduce

Just run it and open the console in a debugger

What is expected?

that the target variable is type checked for being a string before trying to perform the key in target line, to prevent a big error message

What is actually happening?

a big error message comes up


I'm going to have a look at a fix for it now so I'll post it if I figure it out

@lopugit
Copy link
Author

lopugit commented Jan 4, 2018

So I believe that this fix is appropriate. Because you are setting on a string, which you can do.. but really actually can't.

String variables seem a bit.............. weird

Take a look at this:
https://jsfiddle.net/49gptnad/906/

I think it's alright to simply make the code say this:

if (target.constructor !== String && key in target && !(key in Object.prototype)) {
    target[key] = val
    return val
  } else if (target.constructor == String) {
    return undefined
  }

because properties set on strings are always undefined, so technically the value is being set as the value but then becoming undefined on the next tick..

as evidenced when you open a node terminal, and type let word = 'word`` and then word.letter = 'a'` the terminal will output 'a' for some reason, and no error, and also when you console.log(word.letter = 'a'), but, straight after when you try to access this property via it's key, it will be undefined, so, I don't see any harm in returning undefined

@posva
Copy link
Member

posva commented Jan 4, 2018

Feel free to submit a PR that adds a warning on development mode (+ the test ofc 😄 )

@lopugit
Copy link
Author

lopugit commented Jan 4, 2018

@posva there won't be any issues with reactivity?

@posva
Copy link
Member

posva commented Jan 4, 2018

$set must be used on an object anyways

@posva
Copy link
Member

posva commented Jan 11, 2018

Yes, you can look how warnings are implemented and tested and add a warning for the set method

@jaystarshot
Copy link

will look into vue ,will get ready then start working with you guys....

@ismailarilik
Copy link
Contributor

Hi. I have sent a pull request about this issue: #7452

@tugayilik
Copy link

tugayilik commented Jan 17, 2018

According to documentation, https://vuejs.org/v2/api/#vm-set

you are supposed to be using it in this way, i think;

this.$set(this.$data, 'testObj', 'bar');

@Ibrohim005
Copy link

help me please guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants