Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with hxtsdgen #91

Open
fullofcaffeine opened this issue May 10, 2019 · 4 comments
Open

Usage with hxtsdgen #91

fullofcaffeine opened this issue May 10, 2019 · 4 comments
Labels

Comments

@fullofcaffeine
Copy link

fullofcaffeine commented May 10, 2019

I currently have a fork of hxgenjs that integrates hxdtsgen (plan to submit a PR soon) to generate more complete d.ts files for each of the generated js classes. I'm using those to consume Haxe classes from TS. See: https://community.haxe.org/t/gist-sample-ts-haxe-bridge-fullstack-app-using-hxgenjs/1704 and https://github.com/haxe-boilerplate/pwa-ts-haxe-sample.

  1. I'm wondering if haxe-modular would work well with hxdtsgen. I assume it would fail as the post-processor would not be aware of the main.d.ts file?

What I'd like to do is to experiment using haxe-modular with hxtsdgen, maybe through haxe-webpack-loader, and be able to do something like this:

import * as hx from "app.hxml"; 

// Have ts type hints here
var classFoo = new hx.package.ClassFoo()
var classBar = new hx.anotherpackage.ClassBar()

EDIT:
2) Also, as a side-question, hxgenjs allows me to transparently target nodejs and the browser, in fact, hxgenjs doesn't care about that, it just outputs the js files, and I separate them per package (client and server), see here: https://github.com/haxe-boilerplate/pwa-ts-haxe-sample/blob/master/build.hxml. Webpack then processes the client files and typescript does its job with the server files (ts and js files).

Would that be feasible to reproduce when using haxe-modular or is it only geared towards the browser only?

Any insights appreciated :)

Thanks in advance!

@elsassph
Copy link
Owner

Modular supports node - either through Webpack with the Haxe loader, or using -lib modular -lib hxnodejs.

I'll need to think about the Typescript definitions question... It will be problematic with the Webpack Haxe loader because the JS is in memory so I don't know how the TS compiler would find the d.ts. Unless you're hacking quite deeply in tsc it requires physical js/dts on disk.

@elsassph
Copy link
Owner

hxtsdgen should work with Modular, that is the non-Webpack splitting.

I don't believe it can work with the Webpack Haxe Loader, because Haxe compilation happens dynamically when Webpack "loads" hxmls. The TypeScript compiler isn't aware of what Webpack loaders do. It would require pretty deep access to the TS compiler API to maybe implement a custom module resolver, but that isn't exposed in usual TS loaders.

@fullofcaffeine
Copy link
Author

Couldn't we just generate the d.ts for the given hxml output file, akin to what https://github.com/seek-oss/css-modules-typescript-loader does?

@elsassph
Copy link
Owner

Er... would a .hxml.d.ts be picked by Typescript? This is something I didn't consider...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants