Lately, I've been working on creating a type library for a JavaScript written library. As I was defining all the namespaces, classes, and interfaces, I encountered an error TS2417
with some of the classes. I double-checked for any issues with method or property overrides but couldn't pinpoint the problem. After some investigation, I realized that the problematic class had the same name as one of the namespaces (e.g., class A.B
and namespace A.B
). Interestingly, this naming conflict did not initially cause any problems. However, the issue arose from the parent class of the problematic class, which shared the same name as both the problematic class and its namespace. Furthermore, these conflicting names were associated with another class within each respective namespace that had different interfaces. It may be difficult to convey the complexity of the issue, so here is a simulation.
Therefore, the question arises: what is causing this issue?
In the provided example, the troubled class is A.C
, facing compatibility issues due to conflicting constructors in classes A.C.X
and A.B.X
.
declare namespace A {
class B {
}
namespace B {
class X {
}
}
class C extends A.B {
}
namespace C {
class X {
constructor(x: number)
}
}
}