Cannot redeclare block-scoped variable error

Asked

Viewed 58 times

0

Whenever I declare in typescript, a variable, like the one below, I get the following error:

Cannot redeclare block-scoped variable

let input1 = document.getElementById("input1")

Searching google, I saw that just add the word export at the beginning, getting like this:

export{}
let input1 = document.getElementById("input1");

This solves the problem... But when compiling the typescript file, it generates a JS like this:

"use strict";
exports.__esModule = true;
var input1 = document.getElementById("input1");

And then, because of that exports.__esModule = true; the JS does not work..

Practically..

I) If I don’t use Exports at the beginning of typescript code, it keeps giving error saying that this variable already exists in the scope. Obviously it exists because it generates the . JS
II) The solution would be to put export, which solves the error in typescript, but causes . JS not to work..
III) If I don’t put export, the error comes back, it compiles the same and JS works... But it’s the same as the IDE showing me the error.. How to fix this?

  • And if instead of redeclaring let input1 = document.getElementById("input1"); only overwrite input1 = document.getElementById("input1");

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.