question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Error when I specify "declare class" and "function" with the same name

See original GitHub issue

💻

  • Would you like to work on a fix?

How are you using Babel?

@rollup/plugin-babel

Input code

REPL

declare class A {}

function A () {}

Configuration file name

.babelrc

Configuration

{
  "presets": ["@babel/preset-typescript"]
}

Current and expected behavior

I expect this construction to be compiled correctly because tsc can do it. However, currently Babel throws an error:

Duplicate declaration "A"
  1 | declare class A {}
  2 |
> 3 | function A () {}
    | 

Environment

  • Babel version(s): 7.15.5
  • Node: 16
  • npm: 7
  • OS: Windows 10
  • Monorepo: no

Possible solution

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
JLHwungcommented, Nov 29, 2021

Good question. You can build the AST and manually assign declare to it

const decl = t.classDeclaration(...);
decl.declare = true;
1reaction
fedecicommented, Sep 4, 2021

I can look into this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class method and variable with same name, compile error in ...
This way you have members with the same name, but with different addresses. Though isVal variable is hidden by isVal function in the...
Read more >
Erroneous error "Method with same name already defined in ...
What steps will reproduce the problem? 1. Create a class 2. Declare two methods returning a reference (i.e. "function &<methodName>()") with a distinct...
Read more >
Declared property first conflicts when function parameters of ...
Basically Anytime you Define a class field/property and then later on a function that uses a parameter with the same name the UBT...
Read more >
unable to define local function because it has the same name ...
Is there only a way to overcome this problem ? I though that in matlab function where forced to be set in files...
Read more >
Bug Patterns - Error Prone
The called constructor accepts a parameter with the same name and type as one of its caller's parameters, but its caller doesn't pass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found