How does one use Routes in Express?

Ahh I see what’s happening there – in ts, Router is both a function type and an interface type. In haxe it has to be one or the other. Here, app.use() wants Router to be a function type ‘RequestHandler’. The trick we used was to add @:selfCall to Router so that it can have a function type associated, and the same works here; try this instead

app.use('/story', storyRouter.call)

I’ve added this to the dts2hx express example (and verified everything works as expected)

Maybe I can use an abstract wrapper around typedefs to enable automatic unification with the selfCall (this is the same idea as I mentioned here Working with externs for the popular Winston logger (NodeJS) - #2 by haxiomic so it will take a while to complete)

1 Like