diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index aebed60f..31303f56 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -97,6 +97,7 @@ Generated by [AVA](https://avajs.dev). export class ClassWithFactory {␊ name: string␊ static withName(name: string): ClassWithFactory␊ + setName(name: string): this␊ }␊ export namespace xxh3 {␊ export const ALIGNMENT: number␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index 82a6b45b..1357fa79 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/__test__/values.spec.ts b/examples/napi/__test__/values.spec.ts index fa6a3e23..ecd626a0 100644 --- a/examples/napi/__test__/values.spec.ts +++ b/examples/napi/__test__/values.spec.ts @@ -112,6 +112,10 @@ test('class factory', (t) => { const duck = ClassWithFactory.withName('Default') t.is(duck.name, 'Default') + const ret = duck.setName('D') + t.is(ret.name, 'D') + t.is(ret, duck) + duck.name = '周黑鸭' t.is(duck.name, '周黑鸭') diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 93e7c921..d9afc5fd 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -87,6 +87,7 @@ export class Context { export class ClassWithFactory { name: string static withName(name: string): ClassWithFactory + setName(name: string): this } export namespace xxh3 { export const ALIGNMENT: number diff --git a/examples/napi/src/class_factory.rs b/examples/napi/src/class_factory.rs index 116f9772..50daac52 100644 --- a/examples/napi/src/class_factory.rs +++ b/examples/napi/src/class_factory.rs @@ -9,4 +9,10 @@ impl ClassWithFactory { pub fn with_name(name: String) -> Self { Self { name } } + + #[napi] + pub fn set_name(&mut self, name: String) -> &Self { + self.name = name; + self + } }