Presently, I am immersed in a project involving three.js and TypeScript. It has come to my attention that for organizing elements, the Group class is highly recommended. However, I have noticed that the type definitions for Group
do not include a feature like this:
meshGroup = new Group<Mesh>()
where the meshGroup.children
property is exclusively comprised of Meshes.
My attempt was to create a custom type like this:
declare class MeshGroup extends Group {
children: Mesh[]
add(...object: Mesh[]): this
}
meshGroup = new MeshGroup()
Unfortunately, I encountered this console error:
_classes_MeshGroup__WEBPACK_IMPORTED_MODULE_16__.MeshGroup is not a constructor
I searched for a simple way to implement such a wrapper in TypeScript, but without success.
Another approach I considered was to implement a typed array like this:
meshGroup: Mesh[] = []
and maintain synchronization with the class to manage the types, but this adds another layer of complexity.
As I am not an expert in TypeScript, I am wondering if there is a quick type definition trick to implement this "wrapper" definition?