haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
131 stars 8 forks source link

express example build error #95

Closed CrazyFlasher closed 2 years ago

CrazyFlasher commented 2 years ago
PS C:\work\projects\hxnodelibs\examples> haxe build.hxml
Empty.hx:19: lines 19-23 : Could not find a suitable overload, reasons follow
Empty.hx:19: lines 19-23 : Overload resolution failed for (handlers : haxe.extern.Rest<express_serve_static_core.RequestHandler<express_serve_static_core.ParamsDictionary, Dynamic, Dynamic, qs.ParsedQs, { }>>) -> express_serve_static_core.Router
Empty.hx:21: characters 4-22 : express_serve_static_core.NextFunction should be () -> Void
Empty.hx:21: characters 4-22 : ... For function argument 'handlers'
Empty.hx:19: lines 19-23 : Overload resolution failed for (handlers : haxe.extern.Rest<express_serve_static_core.RequestHandlerParams<express_serve_static_core.ParamsDictionary, Dynamic, Dynamic, qs.ParsedQs, { }>>) -> express_serve_static_core.Router
Empty.hx:19: lines 19-23 : (req : express_serve_static_core.Request<express_serve_static_core.ParamsDictionary, Dynamic, Dynamic, qs.ParsedQs, { }>, res : express_serve_static_core.Response<Dynamic, { }, Float>, next : (() -> Void)) -> Void should be express_serve_
static_core.RequestHandlerParams<express_serve_static_core.ParamsDictionary, Dynamic, Dynamic, qs.ParsedQs, { }>
Empty.hx:19: lines 19-23 : ... For function argument 'handlers'
CrazyFlasher commented 2 years ago

issue with haxe 4.2.3 on this line:

(next: () -> Void)();
haxiomic commented 2 years ago

Just re-ran the express example with 4.2.3 and latest @types/express and didn't have the error so cannot repro – my steps were (in an empty directory):

build.hxml

--main Main
--js main.js
--library express

Main.hx

function main() {
    /**
        Express Hello World Example with Router

        For a discussion on this example see this thread:
        https://community.haxe.org/t/how-does-one-use-routes-in-express/2701
    **/
    var app = Express.call();
    var port = 3000;
    app.get('/', (req, res, next) -> res.send('Hello World! <a href="/birds">/birds</a>'));
    app.listen(port, () -> trace('Example app listening at http://localhost:${port}'));

    app.get('/route', (req, res, next) -> res.send('Example route'));

    var router = express.Router.call_();

    // middleware that is specific to this router
    router.use(function timeLog (req, res, next) {
        trace('Time: ' + Date.now());
        (next: () -> Void)();
        return null;
    });

    // define the home page route
    router.get('/', (req, res, next) -> {
        res.send('Birds home page');
    });

    // define the about route
    router.get('/about', (req, res, next) -> {
        res.send('About birds');
    });

    app.use('/birds', router.call);
}

Is yours the same? Maybe the haxe code is a little different?