Quellcode durchsuchen

#19303 Added additional type information to Vector and Matrix toArray() methods. This allows code involving the spread operator for function parameters (which works as expected) to compile in TypeScript.

Antony74 vor 4 Jahren
Ursprung
Commit
c5318a3cd6
5 geänderte Dateien mit 26 neuen und 0 gelöschten Zeilen
  1. 7 0
      src/math/Matrix3.d.ts
  2. 9 0
      src/math/Matrix4.d.ts
  3. 3 0
      src/math/Vector2.d.ts
  4. 4 0
      src/math/Vector3.d.ts
  5. 3 0
      src/math/Vector4.d.ts

+ 7 - 0
src/math/Matrix3.d.ts

@@ -1,6 +1,12 @@
 import { Matrix4 } from './Matrix4';
 import { Vector3 } from './Vector3';
 
+type Matrix3tuple = [
+	number, number, number,
+	number, number, number,
+	number, number, number,
+];
+
 /**
  * ( interface Matrix<T> )
  */
@@ -125,6 +131,7 @@ export class Matrix3 implements Matrix {
 	 * @return The created or provided array.
 	 */
 	toArray( array?: number[], offset?: number ): number[];
+	toArray( array?: Matrix3tuple, offset?: 0 ): Matrix3tuple;
 
 	/**
 	 * Copies he values of this matrix into the provided array-like.

+ 9 - 0
src/math/Matrix4.d.ts

@@ -2,6 +2,14 @@ import { Vector3 } from './Vector3';
 import { Euler } from './Euler';
 import { Quaternion } from './Quaternion';
 import { Matrix } from './Matrix3';
+
+type Matrix4tuple = [
+	number, number, number, number,
+	number, number, number, number,
+	number, number, number, number,
+	number, number, number, number,
+];
+
 /**
  * A 4x4 Matrix.
  *
@@ -235,6 +243,7 @@ export class Matrix4 implements Matrix {
 	 * @return The created or provided array.
 	 */
 	toArray( array?: number[], offset?: number ): number[];
+	toArray( array?: Matrix4tuple, offset?: 0 ): Matrix4tuple;
 
 	/**
 	 * Copies he values of this matrix into the provided array-like.

+ 3 - 0
src/math/Vector2.d.ts

@@ -1,6 +1,8 @@
 import { Matrix3 } from './Matrix3';
 import { BufferAttribute } from './../core/BufferAttribute';
 
+type Vector2tuple = [number, number];
+
 /**
  * ( interface Vector<T> )
  *
@@ -427,6 +429,7 @@ export class Vector2 implements Vector {
 	 * @return The created or provided array.
 	 */
 	toArray( array?: number[], offset?: number ): number[];
+	toArray( array?: Vector2tuple, offset?: 0 ): Vector2tuple;
 
 	/**
 	 * Copies x and y into the provided array-like.

+ 4 - 0
src/math/Vector3.d.ts

@@ -8,6 +8,9 @@ import { Cylindrical } from './Cylindrical';
 import { BufferAttribute } from './../core/BufferAttribute';
 import { InterleavedBufferAttribute } from './../core/InterleavedBufferAttribute';
 import { Vector } from './Vector2';
+
+type Vector3tuple = [number, number, number];
+
 /**
  * 3D vector.
  *
@@ -284,6 +287,7 @@ export class Vector3 implements Vector {
 	 * @return The created or provided array.
 	 */
 	toArray( array?: number[], offset?: number ): number[];
+	toArray( array?: Vector3tuple, offset?: 0 ): Vector3tuple;
 
 	/**
 	 * Copies x, y and z into the provided array-like.

+ 3 - 0
src/math/Vector4.d.ts

@@ -4,6 +4,8 @@ import { Matrix3 } from './Matrix3';
 import { BufferAttribute } from './../core/BufferAttribute';
 import { Vector } from './Vector2';
 
+type Vector4tuple = [number, number, number, number];
+
 /**
  * 4D vector.
  *
@@ -211,6 +213,7 @@ export class Vector4 implements Vector {
 	 * @return The created or provided array.
 	 */
 	toArray( array?: number[], offset?: number ): number[];
+	toArray( array?: Vector4tuple, offset?: 0 ): Vector4tuple;
 
 	/**
 	 * Copies x, y, z and w into the provided array-like.