Fix TypeScript definition for async_fail_in_to_napi_value

Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-23 05:45:21 +00:00
parent d57c03fab8
commit 48853b1fb8
2 changed files with 17 additions and 2 deletions

View File

@ -388,7 +388,14 @@ export declare function arrayParams(arr: Array<number>): number
export declare function asyncBufferToArray(buf: ArrayBuffer): Array<number>
export declare function asyncFailInToNapiValue(): Promise<FailToNapiValue>
/**
* Test function that returns a type which fails during to_napi_value conversion.
* This tests that errors from ToNapiValue::to_napi_value properly reject the promise
* instead of throwing synchronously.
*
* The promise will always be rejected with "Fail in to_napi_value" error.
*/
export declare function asyncFailInToNapiValue(): Promise<never>
export declare function asyncMultiTwo(arg: number): Promise<number>

View File

@ -86,6 +86,9 @@ pub fn extends_javascript_error(env: Env, error_class: Function<String>) -> Resu
Ok(())
}
/// A struct that intentionally fails during conversion to JS value.
/// Used to test error handling in async functions when ToNapiValue::to_napi_value returns an error.
/// Note: This struct is not exported to JS and cannot be used directly from JavaScript.
pub struct FailToNapiValue;
impl ToNapiValue for FailToNapiValue {
@ -94,7 +97,12 @@ impl ToNapiValue for FailToNapiValue {
}
}
#[napi]
/// Test function that returns a type which fails during to_napi_value conversion.
/// This tests that errors from ToNapiValue::to_napi_value properly reject the promise
/// instead of throwing synchronously.
///
/// The promise will always be rejected with "Fail in to_napi_value" error.
#[napi(ts_return_type = "Promise<never>")]
pub async fn async_fail_in_to_napi_value() -> FailToNapiValue {
FailToNapiValue
}