How to make VS Code recognize the ES7 bind operator
Asked Answered
V

1

6

VS Code does not recognize the ES7 bind syntax out of the box. Instead, it shows up as a syntax error:

Example of highlighted error in code

[ts] Declaration or statement expected.
  • I've searched around to see if there's an extension that can help recognize it to no avail.
  • I've also tried to configure VS Code to use my own .eslintrc, which also doesn't seem to work. So far I haven't even been able to confirm VS Code recognizes my .eslintrc file and is using it for its own config.

Does anyone have an idea of how to configure VS Code to recognize the syntax? I realize it's a Stage 0 feature, however I feel it's fairly common at this point. I also realize what I'm seeing is a TypeScript error, however disabling TypeScript linting does not remove the error. I think it just shows up as a TypeScript error, inherited from JavaScript.

After a lot of searching, there's so many articles on how it can be used, but almost nothing when it comes to VS Code.

Victor answered 10/10, 2018 at 22:15 Comment(3)
"I realize it's a Stage 0 feature" yet you call it an ES 7 feature. "however I feel it's fairly common at this point" Any evidence on that? It's neither part of JavaScript nor TypeScript, so I suggest not to use it in production.Hammons
Hello and thanks for your comment. "I suggest not to use it in production." — Just to be clear we're talking about Stage 0 code that is going through the Babel transpiler. I'm not asking if I can use it in production. I'm asking about this specific error. ["foo", "bar"]::toClassName() will be converted to toClassName.call(["foo","bar"]) So I would agree with you. The bind syntax should not be used in production. Your comment isn't adding to the discussion.Victor
The problem is about the TypeScript compiler, not about Babel nor VS Code. You cannot use this feature with TS because it's neither part of the ES standard nor supported by TS. In case I was ambiguous: I suggested not to use the bind syntax at all. Not even in your source code before transpilation.Hammons
H
6

If you use Typescript, this is a Typescript error (although you would get the same error with JS). And Typescript is not planning to support the operator, mainly because the TC39 proposal is dead. There are not yet plans to support it in JS or TS, only Babel does (experimentally). It is not ES7, and it is not even planned to be in the specs somewhen, so it is a SyntaxError for a good reason.

After a lot of searching, there's so many articles on how it can be used

If those articles didn't mention that the operator is still in an early proposal phase, I wouldn't use them as reliable ressources anymore.

Hermaherman answered 10/10, 2018 at 22:31 Comment(1)
There is a new iteration on the proposal that has reached Stage 1 github.com/tc39/proposal-extensionsBrigham

© 2022 - 2024 — McMap. All rights reserved.