1

I have written a simple Vector3 class in assemblyscript. The code compiles just fine but the typescript syntax highlighter naturally doesn't understand the operator overloads. Is there a way for typescript to resolve the type from assemblyscript operator overloading?

Code:

const a = new Vector3()
const b = new Vector3()

const c = a + b //red squigglies

//escape hatch method - works but unideal
//@ts-ignore
const d = <Vector3>a + b 


Error Message:

error message

Class Definition:

export class Vector3{
    x: f32
    y: f32
    z: f32
    constructor(x: f32 = 0, y: f32 = 0, z: f32 = 0){
        this.x = x
        this.y = y
        this.z = z
    }

    @operator('+')
    __op(other: Vector3): Vector3  {
        return new Vector3(
            this.x + other.x,
            this.y + other.y,
            this.z + other.z
        )
    }
}

chantey
  • 4,252
  • 1
  • 35
  • 40
  • 1
    Have not heard about operator overloading in assembly script. Could you please share some link to docs? Anyway, operator overloadins is not something that is supported by typescript – captain-yossarian from Ukraine Feb 17 '22 at 10:08
  • good idea, link added.. ts can do *some* overloading, ie `1 + 'a'` resolves to a string, i guess im wondering if tools like ts syntax highlighting or eslint have access to that kind of thing. – chantey Feb 17 '22 at 10:59

0 Answers0