From 9bde38007dcc91975abcb6d44643e2af36c0b2dd Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 20 Jul 2023 18:35:36 -0400 Subject: [PATCH] Support ByteBuf --- tsify-macros/src/typescript.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tsify-macros/src/typescript.rs b/tsify-macros/src/typescript.rs index 25fd6ae..11edd5f 100644 --- a/tsify-macros/src/typescript.rs +++ b/tsify-macros/src/typescript.rs @@ -321,6 +321,17 @@ impl TsType { Self::Array(Box::new(elem)) } + "ByteBuf" => { + if cfg!(feature = "js") { + Self::Ref { + name: String::from("Uint8Array"), + type_params: vec![], + } + } else { + Self::Array(Box::new(Self::NUMBER)) + } + } + "Option" if args.len() == 1 => Self::Option(Box::new(Self::from_syn_type(args[0]))), "Result" if args.len() == 2 => { @@ -735,12 +746,14 @@ mod tests { assert_ts!(HashMap | BTreeMap, "Map"); assert_ts!(Option, "number | undefined"); assert_ts!(Vec> | VecDeque> | LinkedList> | &'a [Option], "(T | undefined)[]"); + assert_ts!(ByteBuf, "Uint8Array"); } else { assert_ts!((), "null"); assert_ts!(u128 | i128, "number"); assert_ts!(HashMap | BTreeMap, "Record"); assert_ts!(Option, "number | null"); assert_ts!(Vec> | VecDeque> | LinkedList> | &'a [Option], "(T | null)[]"); + assert_ts!(ByteBuf, "number[]"); } assert_ts!(