feat(napi-derive): support renmae function args and return type
This commit is contained in:
parent
e6f341f632
commit
e2e3ef95f8
11 changed files with 54 additions and 5 deletions
examples/napi
|
@ -42,6 +42,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function createExternalString(content: string): ExternalObject<string>␊
|
||||
export function getExternal(external: ExternalObject<number>): number␊
|
||||
export function mutateExternal(external: ExternalObject<number>, newVal: number): void␊
|
||||
export function tsRename(a: { foo: number }): string[]␊
|
||||
export function xxh64Alias(input: Buffer): BigInt␊
|
||||
export function mapOption(val?: number | undefined | null): number | undefined | null␊
|
||||
export function add(a: number, b: number): number␊
|
||||
|
|
Binary file not shown.
|
@ -55,6 +55,7 @@ import {
|
|||
xxh2,
|
||||
xxh3,
|
||||
xxh64Alias,
|
||||
tsRename,
|
||||
} from '../'
|
||||
|
||||
test('export const', (t) => {
|
||||
|
@ -194,6 +195,10 @@ test('Result', (t) => {
|
|||
t.throws(() => throwError(), null, 'Manual Error')
|
||||
})
|
||||
|
||||
test('function ts type override', (t) => {
|
||||
t.deepEqual(tsRename({ foo: 1, bar: 2, baz: 2 }), ['foo', 'bar', 'baz'])
|
||||
})
|
||||
|
||||
test('serde-json', (t) => {
|
||||
const packageJson = readPackageJson()
|
||||
t.is(packageJson.name, 'napi-rs')
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -32,6 +32,7 @@ export function createExternal(size: number): ExternalObject<number>
|
|||
export function createExternalString(content: string): ExternalObject<string>
|
||||
export function getExternal(external: ExternalObject<number>): number
|
||||
export function mutateExternal(external: ExternalObject<number>, newVal: number): void
|
||||
export function tsRename(a: { foo: number }): string[]
|
||||
export function xxh64Alias(input: Buffer): BigInt
|
||||
export function mapOption(val?: number | undefined | null): number | undefined | null
|
||||
export function add(a: number, b: number): number
|
||||
|
|
6
examples/napi/src/fn_ts_override.rs
Normal file
6
examples/napi/src/fn_ts_override.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use napi::bindgen_prelude::{Object, Result};
|
||||
|
||||
#[napi(ts_args_type = "a: { foo: number }", ts_return_type = "string[]")]
|
||||
fn ts_rename(a: Object) -> Result<Object> {
|
||||
a.get_property_names()
|
||||
}
|
|
@ -16,6 +16,7 @@ mod either;
|
|||
mod r#enum;
|
||||
mod error;
|
||||
mod external;
|
||||
mod fn_ts_override;
|
||||
mod js_mod;
|
||||
mod nullable;
|
||||
mod number;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue