[SOLVED] cannot redeclare block scoped variable (typescript)


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

enter image description here

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?


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

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:

  1. Rename the variable, or

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

    export {};


  3. Configure your compiler options by not adding DOM typings:

Edit tsconfig.json in the TypeScript project directory.

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

Answered By – Neville Omangi

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *