Looking to add a lightweight layer on top of Float32Array to create vec2 and vec3's. Check out the example below:
class vec3 extends Float32Array {
// w : number;
constructor() {
super(3);
// this.w = 1;
}
static add3(x: vec3) : vec3 {
x[2] += 1;
return x;
}
};
class vec2 extends Float32Array {
constructor() {
super(2);
}
static add2(x: vec2) : vec2 {
x[1] += 1;
return x;
}
};
var test1: vec3 = new vec3();
vec3.add3(test1);
console.log(test1);
var test2: vec2 = new vec2();
vec3.add3(test2); // Expect an error here
console.log(test2);
(Run code in TS playground here)
Typescript currently sees these classes as equivalent, hence allowing the
vec3.add3(test2);
If I uncomment the line defining the w member variable, it correctly identifies them as distinct classes.
Any suggestions on how to distinguish between these two classes?