When compiling three.d.ts
(which can be found at this link) using the TypeScript develop
branch, an error occurs with the following message:
Types of static property 'Utils' of class 'THREE.Shape' and class 'THREE.Path'
are incompatible
The issue arises because
Shape
defines a staticUtils
classShape
indirectly inherits fromCurve
Curve
also defines a staticUtils
class with a different signature compared toShape.Utils
This violates the language specifications. In essence, the problematic code in three.d.ts
looks something like:
declare class A {
static Utils: {
f (): any;
}
}
declare class B extends A {
static Utils: {
// incompatible with A.Utils, without f(): any
g (): any;
}
}
Ignoring the debate about why the type of a static member needs to be compatible with that of an inherited static member with the same name - a rule not observed in other object-oriented languages but seemingly enforced in TypeScript - the focus is on resolving the compilation issue for three.d.ts
.
One current workaround involves manually replicating the signature of Curve.Utils
into Shape.Utils
, ensuring structural extension between them. However, what is the correct method to accurately represent the signature of the original three.js
file (found here) within a .d.ts
file? Is this a case of improper inheritance implementation?