ts-macros icon indicating copy to clipboard operation
ts-macros copied to clipboard

[BUG] I'm trying to replicatee something closer to the PROPERTY macro in Qt

Open patrickelectric opened this issue 2 years ago • 1 comments

Describe the bug Does not work inside classes

Code to reproduce

function $property() {
    property = 0
}

$property!()

export class ArduPilotSub extends Vehicle.Abstract {
    $property!()

    constructor() {
        super(Vehicle.Firmware.ArduPilot, Vehicle.Type.Sub)
    }
}

link

Expected behavior The output would be something like:

export class ArduPilotSub extends Vehicle.Abstract {
    property = 0;
    constructor() {
        super(Vehicle.Firmware.ArduPilot, Vehicle.Type.Sub);
    }
}

Ref: https://doc.qt.io/qt-5/properties.html

Additional context It would be nice to have more examples, like: How do I use a type as a parameter. $macro!(number, test, 0) Generating something like: const test: number = 0

patrickelectric avatar May 26 '22 19:05 patrickelectric

Yeah, this is not possible currently because macro calls are just regular function calls, you can only use them where you can call functions :(.

As of using a macro parameter as a type - this isn't really possible either because code generated from macros is not type-checked.

GoogleFeud avatar May 27 '22 06:05 GoogleFeud