Code Monkey home page Code Monkey logo

export_ts_macro's Introduction

Macro to derive wasm-bindgen Typescript definitons from structs.

⚠️ Early WIP!

⚠️ Found library that does this: tsify -> stopping work.

Install

export_ts_macro={ git = "https://github.com/ivanschuetz/export_ts_macro", branch = "main" }

Usage

use export_ts_macro::export_ts;
use wasm_bindgen::prelude::*;

#[export_ts(FooTs)]
struct Foo {
    a: i32,
    b: String,
}

#[wasm_bindgen]
pub fn hello(pars: FooTs) {
    let js: JsValue = pars.into();
    let _actual: Foo = js.into_serde().unwrap();
}

This generates the following Typescript:

interface FooTs {
  a: i32;
  b: string;
}

/**
 * @param {FooTs} pars
 */
export function foo(pars: FooTs): void;

Internals

The macro generates code according to the typescript_type section in the wasm-bindgen guide.

#[wasm_bindgen(typescript_custom_section)]
const FooTs: &'static str = r#"
interface FooTs {
    a: number
    b: string
}
"#;

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(typescript_type = "FooTs")]
    pub type FooTs;
}

export_ts_macro's People

Contributors

owlmafia avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.