diff --git a/crates/backend/src/codegen/struct.rs b/crates/backend/src/codegen/struct.rs index 1af55d32..887833c9 100644 --- a/crates/backend/src/codegen/struct.rs +++ b/crates/backend/src/codegen/struct.rs @@ -120,9 +120,9 @@ impl NapiStruct { let ty = &field.ty; match &field.name { syn::Member::Named(ident) => fields - .push(quote! { #ident: <#ty as FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }), + .push(quote! { #ident: <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }), syn::Member::Unnamed(_) => { - fields.push(quote! { <#ty as FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }); + fields.push(quote! { <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, cb.get_arg(#i))? }); } } } @@ -171,11 +171,15 @@ impl NapiStruct { match &field.name { syn::Member::Named(ident) => { field_destructions.push(quote! { #ident }); - field_conversions.push(quote! { <#ty as ToNapiValue>::to_napi_value(env, #ident)? }); + field_conversions.push( + quote! { <#ty as napi::bindgen_prelude::ToNapiValue>::to_napi_value(env, #ident)? }, + ); } syn::Member::Unnamed(i) => { field_destructions.push(quote! { arg #i }); - field_conversions.push(quote! { <#ty as ToNapiValue>::to_napi_value(env, arg #i)? }); + field_conversions.push( + quote! { <#ty as napi::bindgen_prelude::ToNapiValue>::to_napi_value(env, arg #i)? }, + ); } } } diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 4b3b4e40..3fe058e5 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -147,6 +147,11 @@ Generated by [AVA](https://avajs.dev). static withData(data: string): Context␊ method(): string␊ }␊ + export class AnimalWithDefaultConstructor {␊ + name: string␊ + kind: number␊ + constructor(name: string, kind: number)␊ + }␊ export class ClassWithFactory {␊ name: string␊ static withName(name: string): ClassWithFactory␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index b73f0fe8..d60e614e 100644 Binary files a/examples/napi/__test__/typegen.spec.ts.snap and b/examples/napi/__test__/typegen.spec.ts.snap differ diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 3e9dbb64..b46fd4ab 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -137,6 +137,11 @@ export class Context { static withData(data: string): Context method(): string } +export class AnimalWithDefaultConstructor { + name: string + kind: number + constructor(name: string, kind: number) +} 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 a8271527..01984e98 100644 --- a/examples/napi/src/class.rs +++ b/examples/napi/src/class.rs @@ -114,3 +114,9 @@ impl Context { self.data.clone() } } + +#[napi(constructor)] +pub struct AnimalWithDefaultConstructor { + pub name: String, + pub kind: u32, +}