1

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

2
  • 1
    It looks like you have TypeScript configured to treat your JS output directory as an input directory. Are they the same? If you post your tsconfig.json and folder structure, it'd be easier to help configure TypeScript not to treat its output as additional input. Commented Dec 17, 2021 at 1:12
  • Yes - ok. I didnt have one but nor did the tutorial. I added one and it fixed the issue. Thank you Commented Dec 17, 2021 at 1:27

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.