Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
shrinktofit opened this issue Apr 7, 2021 · 2 comments · Fixed by #14109
Closed
1 task

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

shrinktofit opened this issue Apr 7, 2021 · 2 comments · Fixed by #14109
Assignees
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@shrinktofit
Copy link
Contributor

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

@babel-bot
Copy link
Collaborator

Hey @shrinktofit! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@The-x-Theorist
Copy link
Contributor

I'd like to work on this issue?

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants