Home  >  Q&A  >  body text

javascript - typescript 使用const 报Cannot redeclare block-scoped variable

Two files in the same directory a.ts b.ts

a.ts:

const a=1;

b.ts:

const a=2;

The two files have no dependencies, I really can’t figure it out

高洛峰高洛峰2692 days ago1401

reply all(2)I'll reply

  • 黄舟

    黄舟2017-06-30 10:00:05

    Because there is no import or export in your two files, so he thinks that your two files are global... and will naturally prompt this

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-30 10:00:05

    Because there is no closure in the file, each a is a global variable by default. You can use export to export a, then a becomes a variable in the closure.

    reply
    0
  • Cancelreply