microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.08k forks source link

';' expected.ts(1005) error is shown in a .js file #import statement. Using "TypeScript and JavaScript Language Features" #182478

Closed futuremotiondev closed 1 year ago

futuremotiondev commented 1 year ago

Steps to Reproduce:

  1. Enable the "TypeScript and JavaScript Language Features" extension included in VSCode.
  2. Create a new .js file.
  3. Add #include "SomeScript.js"; to the top of the file.
  4. Observe that the extension is marking the line as a problem with the cause of ';' expected.ts(1005)

The #include statement above is perfectly valid JavaScript from what I understand. Why is it throwing a TypeScript error in a JavaScript file?

Code_KNgLSUemOp

mjbvz commented 1 year ago

The #include statement above is perfectly valid JavaScript from what I understand

Not any javascript I'm familiar with. You want import instead: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import