Skip to content

[BUG/TypeScript] declare global conflict with block declaration #13112

Closed
@shrinktofit

Description

Bug Report

  • I would like to work on a fix!

Current behavior

Code

declare global { namespace globalThis { var i18n: any; } }

export class i18n {}

trigger an scope error:

    TypeError: Duplicate declaration "i18n"
      1 | declare global { namespace globalThis { var i18n: any; } }
      2 |
    > 3 | export class i18n {}
        |              ^^^^

      249 |     }
      250 | 
    > 251 |     return new Error(msg);
          |            ^
      252 |   }
      253 | 
      254 | }

      at File.buildCodeFrameError (packages/babel-core/lib/transformation/file/file.js:251:12)
      at Scope.checkBlockScopedCollisions (packages/babel-traverse/lib/scope/index.js:422:22)
      at Scope.registerBinding (packages/babel-traverse/lib/scope/index.js:582:16)
      at Scope.registerDeclaration (packages/babel-traverse/lib/scope/index.js:527:12)
      at Object.BlockScoped (packages/babel-traverse/lib/scope/index.js:250:12)
      at Object.newFn (packages/babel-traverse/lib/visitors.js:216:17)
      at NodePath._call (packages/babel-traverse/lib/path/context.js:55:20)
      at NodePath.call (packages/babel-traverse/lib/path/context.js:38:14)
      at NodePath.visit (packages/babel-traverse/lib/path/context.js:90:31)
      at TraversalContext.visitQueue (packages/babel-traverse/lib/context.js:116:16)

Input Code

As described above.

Expected behavior

This piece of code is valid in TypeScript.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": ["@babel/preset-typescript"]
}

Environment

  • Babel version(s): [e.g. v7.12.0]
  • Node/npm version: [e.g. Node 12/npm 7]
  • OS: [e.g. macOS 10.15.4, Windows 10]
  • Monorepo: [e.g. yes/no/Lerna]
  • How you are using Babel: [e.g. webpack, rollup, parcel, babel-register]

Possible Solution

Additional context

Metadata

Labels

area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions