HiveBrain v1.2.0
Get Started
← Back to all entries
debugtypescriptCriticalCanonical

Cannot redeclare block scoped variable

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
redeclareblockvariablescopedcannot

Problem

I'm building a node app, and inside each file in .js used to doing this to require in various packages.

let co = require("co");


But getting

etc. So using typescript it seems there can only be one such declaration/require across the whole project?
I'm confused about this as I thought let was scoped to the current file.

I just had a project that was working but after a refactor am now getting these errors all over the place.

Can someone explain?

Solution

The best explanation I could get is from Tamas Piro's post.

TLDR;
TypeScript uses the DOM typings for the global execution environment. In your case there is a 'co' property on the global window object.

To solve this:

-
Rename the variable, or

-
Use TypeScript modules, and add an empty export{}:

export {};


or

-
Configure your compiler options by not adding DOM typings:

Edit tsconfig.json in the TypeScript project directory.

{
    "compilerOptions": {
        "lib": ["es6"]
      }
}

Code Snippets

{
    "compilerOptions": {
        "lib": ["es6"]
      }
}

Context

Stack Overflow Q#35758584, score: 184

Revisions (0)

No revisions yet.