Approach to type definition generation for web users #290
ianthetechie
started this conversation in
Engineering RFDs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
Since GSoC 2024, Ferrostar has included support for the web, via WASM cross-compilation and JavaScript bindings. The bindings are what allow easy interoperability between web developers and the core, which is compiled to WASM. Web devs speak JS, sending objects back and forth, and the bindings ensure that happens smoothly.
The generated bindings are vanilla JS for maximum compatibility. However, even among Vanilla JS users, editors are usually capable of consuming information from
.d.ts
files, and nearly all popular JS packages publish definitions either together or in a separate npm package.This document discusses approaches considered to publishing type definitions for the web, what we settled on, and why so that we can effectively re-evaluate as the landscape morphs.
Approaches evaluated
We looked at three crates in total:
ts-rs
@CatMe0w, who did the initial implementation work, did a proof of concept with
ts-rs
in #181. At the time, there were some limitations with how it generated the types, as it initially spread definitions across multiple files. This PR has been merged and made it into release 10.0.0 a few weeks ago. This is no longer an issue, so we could generate a single definition file withts-rs
in the future if we decide it's a better crate.The original implementor also left the above comment on #181 in reference to
ts-rs
:The maintainers did not pursue this issue further, but it presumably solvable.
tsify
Given the above issues faced during GSoC (on which the contributor spent significant time), we suggested looking at
tsify
as an alternative. As you can see in the PR, the changes were minimal, and we are currently using it to generate type definitions.tsify
is a more minimalist crate, but it does appear to be fairly well maintained (a bit less active thants-rs
, but that's not necessarily a bad thing). It does the job of generating a single.d.ts
file automatically as part of thewasm-pack
build.So far,
tsify
seems to do its job well without any hiccups, but in case it ever becomes unmaintained, we can revisitts-rs
.Beta Was this translation helpful? Give feedback.
All reactions