-1

I'm looking at some code in an existing project and came across a js file containing one line:

declare var __DEV__: boolean;

There is a syntax error that says:

Expected ; but found var

I tried removing the declare to change the line to:

var __DEV__: boolean;

which gives the error:

Expected ; but found :

I've also read this post to understand how declarations work and confirm that it's necessary for this part of the code. I then compared the code to examples found here and couldn't pinpoint the mistake.

I considered changing the variable name, or declaring it differently, but I would like to understand how to do this correctly.

Code Maniac
  • 37,143
  • 5
  • 39
  • 60
Manaar
  • 202
  • 4
  • 15

1 Answers1

0

That's a Typescript construct. If you're writing vanilla JS, it doesn't apply.

In vanilla JS, just write

var __DEV__ = true; or var __DEV__ = false;

Jonathan Wilson
  • 4,138
  • 1
  • 24
  • 36
  • I don't think removing/modifying the declaration is the correct approach. The user likely needs to understand that the project is not written in javascript, but needs to be transpiled to javascript. – Jake Holzinger Dec 07 '18 at 20:37
  • 2
    Agreed. I think that this is a yet another instance of the [XY problem](http://xyproblem.info/). – Jonathan Wilson Dec 07 '18 at 20:37