Optional Chaining Coming to JS

This looks cool!

2 Likes

I’ve been using @babel/plugin-proposal-optional-chaining with Meteor/babel for a while now.

The only problem with it is that I can’t get eslint to work with it correctly. It used to work in an old version, but newer versions broke something, and now it kicks up incorrect error messages in some cases.

2 Likes

Yes, and if you’re anything like me, these unresolved errors drive me batty :smiley:

3 Likes

Which version of eslint are you guys using? Im using eslint v5.16.0 and @babel/plugin-proposal-optional-chaining v7.0.0 on webstorm with no issues.

Im also using babel-eslint.

1 Like

I actually had the error resolved at one point, but once I resolved that I ran into runtime errors because the transform wasn’t being applied to the code. I tried for a couple hours to figure out the problem, but at some point I just gave up and got back to work.

1 Like

I think lodash’s get is more powerful. It works with arrays/nested arrays and you can set a default/fallback value as well.
E.g. the example in the blogpost is much shorter with it:

function getWinnerZip(response) {
  return get(response, 'user.address.zipcode', null)
}
3 Likes

_.get and _.set are wicked-awesome functions :muscle:

I’m using whatever the latest is. It used to work perfectly, but an update of babel-eslint after 8.2.1 broke it for some cases, and they never fixed it. I think it improved at some point after 8.2.2, but didn’t fix all the cases. There’s a long standing ticket in github about it.