Skip to content

Commit e433993

Browse files
authored
[three] Revert static is(Vector|Matrix*) changes. (#2129)
Most ThreeJS classes have a is* property on the prototype. This allows for typechecks without using instanceof. Recently the vector and matrix classes change to initialize this property using static initialization block. (PR here: mrdoob/three.js#33140) The types were updated to be 'static readonly isVector3: boolean' which means one can only access isVector3 like this: Vector3.isVector3 which is not useful. While the initialization of the property changed, the shape of the class did not. This commit reverts the type update and restores the previous functionality.
1 parent 50e571e commit e433993

8 files changed

Lines changed: 11 additions & 9 deletions

File tree

types/three/src/math/Matrix2.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type Matrix2Tuple = [
1212
* const m = new Matrix2();
1313
*/
1414
export class Matrix2 {
15-
static readonly isMatrix2: boolean;
15+
readonly isMatrix2: true;
1616

1717
/**
1818
* A {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major} list of matrix values.

types/three/src/math/Matrix3.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Matrix3Tuple = [
1717
];
1818

1919
export class Matrix3 {
20-
static readonly isMatrix3: boolean;
20+
readonly isMatrix3: true;
2121

2222
/**
2323
* Array with matrix values.

types/three/src/math/Matrix4.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type Matrix4Tuple = [
4242
* m.multiply( m3 );
4343
*/
4444
export class Matrix4 {
45-
static readonly isMatrix4: boolean;
45+
readonly isMatrix4: true;
4646

4747
/**
4848
* Array with matrix values.

types/three/src/math/Vector2.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export interface Vector2Like {
1212
* 2D vector.
1313
*/
1414
export class Vector2 {
15-
static readonly isVector2: boolean;
16-
1715
constructor(x?: number, y?: number);
1816

1917
/**
@@ -27,6 +25,7 @@ export class Vector2 {
2725
y: number;
2826
width: number;
2927
height: number;
28+
readonly isVector2: true;
3029

3130
/**
3231
* Sets value of this vector.

types/three/src/math/Vector3.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export interface Vector3Like {
2929
* c.crossVectors( a, b );
3030
*/
3131
export class Vector3 {
32-
static readonly isVector3: boolean;
33-
3432
constructor(x?: number, y?: number, z?: number);
3533

3634
/**
@@ -47,6 +45,7 @@ export class Vector3 {
4745
* @default 0
4846
*/
4947
z: number;
48+
readonly isVector3: true;
5049

5150
/**
5251
* Sets value of this vector.

types/three/src/math/Vector4.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export interface Vector4Like {
1515
* 4D vector.
1616
*/
1717
export class Vector4 {
18-
static readonly isVector4: boolean;
19-
2018
constructor(x?: number, y?: number, z?: number, w?: number);
2119

2220
/**
@@ -41,6 +39,7 @@ export class Vector4 {
4139

4240
width: number;
4341
height: number;
42+
readonly isVector4: true;
4443

4544
/**
4645
* Sets value of this vector.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as THREE from "three";
2+
3+
const texture = new THREE.Vector3();
4+
texture.isVector3; // $ExpectType true

types/three/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"test/unit/src/audio/AudioContext.ts",
3939
"test/unit/src/core/EventDispatcher.ts",
4040
"test/unit/src/core/Uniform.ts",
41+
"test/unit/src/math/Vector3.ts",
4142
"test/unit/src/nodes/display/ColorAdjustment.ts",
4243
"test/unit/src/nodes/materialx/lib/mx_hsv.ts",
4344
"test/unit/src/nodes/materialx/lib/mx_noise.ts",

0 commit comments

Comments
 (0)