Home > database >  Typescript scoped variable with generated javascript file
Typescript scoped variable with generated javascript file

Time:12-17

I'm just learning typescript and following an online course. I've hit a bit of a snag immediately and must be a vscode setting or something?

When I compile app.ts it generates the app.js but immediately I get a typescript error because the person variable is conflicting with the person variable in the app.js which was just generated. The error is "Cannot redeclare block-scoped variable".

Can someone tell me how to avoid this?

app.ts

app.js

CodePudding user response:

Resolved in the comments:

In absence of a tsconfig.json file, TypeScript (built into Visual Studio Code) treated your JS output directory as an input directory. The problem was solved by creating the file; if the file existed, it would require configuring TypeScript not to treat its output as additional input via includes, excludes, or files configurations (or by setting an outFile or outDir).

  • Related