Within the realm of Three.js, there exists a field on the Object3D
class known as userData. This particular property is defined in the type declaration file
node_modules/three/src/core/Object3D.d.ts
:
/**
* Base class for scene graph objects
*/
export class Object3D extends EventDispatcher {
[...]
/**
* An object that can be used to store custom data about the Object3d. It should not hold references to functions as these will not be cloned.
* @default {}
*/
userData: { [key: string]: any };
[...]
}
In an effort to impose stronger typing on the userData attribute, I crafted a module type declaration named src/typings/three.d.ts
:
declare module 'three' {
export class Object3D {
userData: MyType1 | MyType2;
}
}
type MyType1 = {
type: 'type1';
radius: number;
};
type MyType2 = {
type: 'type2';
name: string;
};
Despite successfully overwriting the userData
property, all other type declarations within the three module were replaced rather than merged. This outcome proved to be more destructive than beneficial, evident in the absence of additional properties.
Is there an effective method to merge type declarations whereby solely the userData
is substituted without impacting the entire module?