diff --git a/crates/backend/src/typegen/struct.rs b/crates/backend/src/typegen/struct.rs index 7f039052..afbe5227 100644 --- a/crates/backend/src/typegen/struct.rs +++ b/crates/backend/src/typegen/struct.rs @@ -73,13 +73,13 @@ impl NapiStruct { .fields .iter() .filter(|f| f.getter) - .map(|f| { - let mut field_str = String::from(""); - + .filter_map(|f| { if f.skip_typescript { - return field_str; + return None; } + let mut field_str = String::from(""); + if !f.comments.is_empty() { field_str.push_str(&js_doc_from_comments(&f.comments)) } @@ -95,7 +95,7 @@ impl NapiStruct { } field_str.push_str(&arg); - field_str + Some(field_str) }) .collect::>() .join("\\n"); diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 5ee6c2fc..d498072d 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -146,6 +146,13 @@ export class AnimalWithDefaultConstructor { kind: number constructor(name: string, kind: number) } +export class NinjaTurtle { + name: string + /** Create your ninja turtle! 🐢 */ + static newRaph(): NinjaTurtle + getMaskColor(): string + getName(): string +} export class ClassWithFactory { name: string static withName(name: string): ClassWithFactory diff --git a/examples/napi/src/class.rs b/examples/napi/src/class.rs index 01984e98..063310f6 100644 --- a/examples/napi/src/class.rs +++ b/examples/napi/src/class.rs @@ -120,3 +120,42 @@ pub struct AnimalWithDefaultConstructor { pub name: String, pub kind: u32, } + +// Test for skip_typescript +#[napi] +pub struct NinjaTurtle { + pub name: String, + #[napi(skip_typescript)] + pub mask_color: String, +} + +#[napi] +impl NinjaTurtle { + /// Create your ninja turtle! 🐢 + #[napi(factory)] + pub fn new_raph() -> Self { + Self { + name: "Raphael".to_owned(), + mask_color: "Red".to_owned(), + } + } + + /// We are not going to expose this character, so we just skip it... + #[napi(factory, skip_typescript)] + pub fn new_leo() -> Self { + Self { + name: "Leonardo".to_owned(), + mask_color: "Blue".to_owned(), + } + } + + #[napi] + pub fn get_mask_color(&self) -> &str { + self.mask_color.as_str() + } + + #[napi] + pub fn get_name(&self) -> &str { + self.name.as_str() + } +} diff --git a/examples/napi/src/enum.rs b/examples/napi/src/enum.rs index 76ab296b..8f6a928a 100644 --- a/examples/napi/src/enum.rs +++ b/examples/napi/src/enum.rs @@ -28,3 +28,10 @@ pub enum CustomNumEnum { fn enum_to_i32(e: CustomNumEnum) -> i32 { e as i32 } + +#[napi(skip_typescript)] +pub enum SkippedEnums { + One = 1, + Two, + Tree, +} diff --git a/examples/napi/src/lib.rs b/examples/napi/src/lib.rs index c8b76a5d..047c5add 100644 --- a/examples/napi/src/lib.rs +++ b/examples/napi/src/lib.rs @@ -7,6 +7,9 @@ extern crate serde_derive; /// This is a const pub const DEFAULT_COST: u32 = 12; +#[napi(skip_typescript)] +pub const TYPE_SKIPPED_CONST: u32 = 12; + mod array; mod r#async; mod bigint;