vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Add support for ES2016 Object Spread Initializer

Open onybo opened this issue 10 years ago • 37 comments

Object Spread Initializers is a proposed feature of ES2016 and is very useful when writing Redux reducers. The syntax is supported in babel, but when using the feature in Visual Studio Code it will mark the spread operator as a syntax error.

See: https://github.com/sebmarkbage/ecmascript-rest-spread/blob/master/Spread.md for more information of the feature.

It would be very nice if Visual Studio Code did not mark the use of this feature as an error with a red squiggly.

The current behavior in Visual Studio Code is also described in Issue #1640

onybo avatar Jan 13 '16 08:01 onybo

+1 I've been pretty much ignoring my errors and warnings in VSCode in hopes that this would be addressed soon but it's been a few months now. I've also noticed some discussion in the ESLint project about this and their suggestion was to make use of babel-eslint. I wonder if that is possible to use in VSCode...

jpierson avatar Jan 17 '16 03:01 jpierson

This issue was moved to Microsoft/TypeScript#6525

jrieken avatar Jan 18 '16 09:01 jrieken

No point in moving this feature request to the TypeScript project. They already have the feature on their roadmap. It is planned for the 2.0 release of TypeScript.

https://github.com/Microsoft/TypeScript/wiki/Roadmap

I don't understand why Syntax checking of EcmaScript in Visual Studio Code is dependent on TypeScript though? Do you use TypeScript to check the syntax of plain .js files?

onybo avatar Jan 18 '16 09:01 onybo

Yes

jrieken avatar Jan 18 '16 10:01 jrieken

@jrieken shouldn't eslint and babel-eslint be doing that?

kumarharsh avatar Mar 08 '16 12:03 kumarharsh

+1 I can't use VSCode at all b/c of this.. My code uses a ton of obj spread, so I am forced to use a different editor :-1:

marc314 avatar Apr 13 '16 15:04 marc314

Sorry to hear that. Since recent we do have an option to turn off validation for JavaScript - "javascript.validate.enable": false. That setting and a linter extension that supports object spread (like eslint) should bring you in a more comfortable spot.

jrieken avatar Apr 13 '16 15:04 jrieken

@jrieken // Place your settings in this file to overwrite the default settings { "javascript.validate.enable": false } Doesn't seem to effect the red ~ for me... Am I doing it wrong?

image

marc314 avatar Apr 13 '16 15:04 marc314

two questions:

  • what version of vs code are you running?
  • this is a JavaScript file, not TypeScript?

jrieken avatar Apr 13 '16 16:04 jrieken

This is a .js file (not .jsx or .ts)...

image

marc314 avatar Apr 13 '16 16:04 marc314

@dbaeumer Do you have ideas why that is?

jrieken avatar Apr 14 '16 06:04 jrieken

@marc314 Try using the 0.10.15-insider build, and see if it changes... That same code seems to be working fine for me.

kumarharsh avatar Apr 14 '16 07:04 kumarharsh

@jrieken the setting in not available in 0.10.11 (intellisense doesn't propose it either in that build)

dbaeumer avatar Apr 14 '16 08:04 dbaeumer

Ok. mystery solved - @marc314 You got two options: Try out the 0.10.15-insider or wait for the next stable build is coming out very, very soon.

jrieken avatar Apr 14 '16 08:04 jrieken

@jrieken @kumarharsh @dbaeumer Thanks guys! I installed the insider build and it solved my issue. Looking forward to the next stable build as well. Much obliged!

marc314 avatar Apr 14 '16 12:04 marc314

Just updated to v1.0 but spread operator is still marked as an error :disappointed: I've also added jsconfig.json with target es6 to my project, but no luck

albertogasparin avatar Apr 15 '16 08:04 albertogasparin

@albertogasparin Object spread is not es6 but up for es7 discussion. There is a setting to disable validation such that VS Code doesn't complain about the future there.

jrieken avatar Apr 15 '16 08:04 jrieken

Regarding this, as a newcomer to VS Code I found the official docs very helpful.

pavestru avatar Apr 19 '16 09:04 pavestru

To add what @jrieken has, you can use the eslint plugin to have eslint run, it will catch most of the same errors, but may miss some. I'm just ignoring these for now, still annoying.

tracker1 avatar Apr 27 '16 21:04 tracker1

The issue still exists - I'm using VS Code 1.7 and ESLint plugin for React.js

DennisBecker avatar Nov 08 '16 12:11 DennisBecker