cannot redeclare block scoped variable (typescript)

后端 未结 8 1199
醉话见心
醉话见心 2020-12-08 18:02

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 gett

8条回答
  •  悲哀的现实
    2020-12-08 18:48

    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:

    1. Rename the variable, or
    2. Use TypeScript modules, and add an empty export{}:
    export {};
    

    or

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

    Edit tsconfig.json in the TypeScript project directory.

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

提交回复
热议问题