You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to create a subclass of Matrix4 to add my own custom methods while maintaining type safety.
However, when using functions like .multiply, the subclass is "lost", because it returns type Matrix4.
In reality, .multiply is an in-place operation which returns this, so the subclass is preserved.
Example
exportclassMatrix4ExtextendsMatrix4{extension(): this {// -- Do stuff --returnthis;}}newMatrix4Ext().multiply(newMatrix4())// Error: Property 'extension' does not exist on type 'Matrix4'..extension();
Solution
The type definitions should be adjusted to return this instead of Matrix4 if the operation is in-place and this is returned.
Which type definitions have to be adjusted can be inferred from the Three.js documentation on Matrix4 (using the this type).
The text was updated successfully, but these errors were encountered:
Objective
I would like to create a subclass of
Matrix4
to add my own custom methods while maintaining type safety.However, when using functions like
.multiply
, the subclass is "lost", because it returns typeMatrix4
.In reality,
.multiply
is an in-place operation which returnsthis
, so the subclass is preserved.Example
Solution
The type definitions should be adjusted to return
this
instead ofMatrix4
if the operation is in-place andthis
is returned.Which type definitions have to be adjusted can be inferred from the Three.js documentation on Matrix4 (using the
this
type).The text was updated successfully, but these errors were encountered: