diff --git a/crates/backend/src/typegen.rs b/crates/backend/src/typegen.rs index 86aa6092..527e46d7 100644 --- a/crates/backend/src/typegen.rs +++ b/crates/backend/src/typegen.rs @@ -98,6 +98,7 @@ static KNOWN_TYPES: Lazy> = Lazy::new(|| { map.extend([ ("JsUndefined", "undefined"), ("()", "undefined"), + ("Undefined", "undefined"), ("JsNumber", "number"), ("i8", "number"), ("i16", "number"), @@ -152,6 +153,7 @@ static KNOWN_TYPES: Lazy> = Lazy::new(|| { ("Either4", "{} | {} | {} | {}"), ("Either5", "{} | {} | {} | {} | {}"), ("unknown", "unknown"), + ("Null", "null"), ("null", "null"), ("Symbol", "symbol"), ("JsSymbol", "symbol"), diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 4424ebd3..106ed2e6 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -66,6 +66,8 @@ Generated by [AVA](https://avajs.dev). 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 returnNull(): null␊ + export function returnUndefined(): void␊ export function add(a: number, b: number): number␊ export function fibonacci(n: number): number␊ export function listObjKeys(obj: object): Array␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index d3926100..43419afb 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 daefa0ca..b080e2d5 100644 --- a/examples/napi/__test__/values.spec.ts +++ b/examples/napi/__test__/values.spec.ts @@ -65,6 +65,8 @@ import { ALIAS, AliasedStruct, appendBuffer, + returnNull, + returnUndefined, } from '../' test('export const', (t) => { @@ -192,6 +194,14 @@ test('get null', (t) => { } }) +test('return Null', (t) => { + t.is(returnNull(), null) +}) + +test('return Undefined', (t) => { + t.is(returnUndefined(), undefined) +}) + test('pass symbol in', (t) => { const sym = Symbol('test') const obj = setSymbolInObj(sym) diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index ab36c034..5ee6c2fc 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -56,6 +56,8 @@ export function mutateExternal(external: ExternalObject, newVal: number) 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 returnNull(): null +export function returnUndefined(): void export function add(a: number, b: number): number export function fibonacci(n: number): number export function listObjKeys(obj: object): Array diff --git a/examples/napi/src/nullable.rs b/examples/napi/src/nullable.rs index eb52c12c..18a532c8 100644 --- a/examples/napi/src/nullable.rs +++ b/examples/napi/src/nullable.rs @@ -1,4 +1,14 @@ +use napi::bindgen_prelude::*; + #[napi] fn map_option(val: Option) -> Option { val.map(|v| v + 1) } + +#[napi] +fn return_null() -> Null { + Null +} + +#[napi] +fn return_undefined() -> Undefined {}