Rust <-> typescript setup

  1. This needs to run on plain Linux/x86, not web assembly. The reason is that the Rust code is using OpenGL / CUDA bindings.

  2. Is there a standard way to tag certain Rust functions / structs as "TypeScript accessible", and then have a setup where:

2.a We run a typescript repl.
2.b We load the rust code as a module.
2.c We can type typescript code in the typescript repl and manipulate the Rust module ?

1 Like

I don't think Node runs TypeScript natively, but if you can find a way to run a TypeScript repl with node, you can create a native NodeJS module with rust using Neon:

https://github.com/neon-bindings/neon

That would allow you to bind your native Rust code as a JavaScript library which you could interact with in a NodeJS REPL. You would just have to figure out how to work in TypeScript.

1 Like

That would allow you to bind your native Rust code as a JavaScript library which you could interact with in a NodeJS REPL.

I'm currently trying to do something similar myself, including trying to access/manipulate the library from a repl (mainly to figure things out).

Neon doesn't currently generate types (related issue on github), but I was just informed in the slack channel that I could use quicktype (I guess referring to this product?) to programmatically generate types, otherwise it was suggested to just handwrite the types if the api is small enough.

2 Likes

You are ahead of me, so I do not know if I am understanding the problem correctly.

Quoting The `wasm-bindgen` Guide

--typescript
Output a TypeScript declaration file for the generated JavaScript bindings. This is on by default.

--no-typescript
By default, a *.d.ts TypeScript declaration file is generated for the generated JavaScript bindings, but this flag will disable that.

I wonder if there is a wa yto make the "API crate" to also be buildable under wasm and then utilize the above to generate the *.d.ts files.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.