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

Improve TS types #53

Open
tordans opened this issue Apr 1, 2024 · 1 comment
Open

Improve TS types #53

tordans opened this issue Apr 1, 2024 · 1 comment

Comments

@tordans
Copy link
Contributor

tordans commented Apr 1, 2024

It would be great to be able to learn more about the library right from VS Code by using the types, function comments and type files.

Function comments:

It looks like the function comments can be shared between Rust and TS right away, like it is done for debugRenderGraph:

So one step would be to write more detailed function comments that cover the cases in https://github.com/dabreegster/route_snapper/blob/main/user_guide.md#wasm-api. I don't know if new lines will be accepted there, but that would be helpful (like a full JS Doc description block).

Input/output types:

The other part is having detailed input / output types. Right now a lot of them are just string or any. One has to explore the shape of the files even though they are pretty defined by the library:

Example:

/**
- * @param {any} raw_waypoints
+ * @param {{ lon: number, lat: number, snapped: boolean }[]} raw_waypoints
*/
-  editExisting(raw_waypoints: any): void;
+  editExisting(raw_waypoints: { lon: number, lat: number, snapped: boolean }[]): void;

I looked into this a bit (this article sounded good) and it sounded like one need an extra crate like https://lib.rs/crates/tsify to create those better types. Some will auto generate but one can customize this as well.

@dabreegster
Copy link
Owner

Thanks for finding tsify and an article walking through it! This indeed looks promising. I'll try and start on this during this week. There are some unknowns, like expressing the output of renderGeojson -- the Point features and LineString features have different properties. To express that precisely, I might need to write some interesting new types on the Rust side and make sure they serialize to GeoJSON the right way. Or it might be simpler to use some of the wasm-bindgen options to specify a manually written TS block, and not actually have the Rust compilation process verify this is the shape of the output.

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

No branches or pull requests

2 participants