1

我在汇编脚本中编写了一个简单的 Vector3 类。代码编译得很好,但打字稿语法荧光笔自然不理解运算符重载。打字稿有没有办法从汇编脚本运算符重载中解析类型?

代码:

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 


错误信息:

错误信息

类定义:

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
        )
    }
}

4

0 回答 0