diff options
author | 阿豪 <504595380@qq.com> | 2022-12-03 20:15:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-03 17:45:35 +0530 |
commit | 8b5b327b18b1cc6b0519e632d0e9b709af18820e (patch) | |
tree | 8f38b23887fc9b62bd4358e659ebd98ef6c13c53 /cli/tsc | |
parent | 0169949c299f05c62e5964973361217af1432171 (diff) |
feat(ext/ffi): better type hints for Deno.dlopen (#16874)
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index ce609736b..9e91c8800 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -443,7 +443,7 @@ declare namespace Deno { /** The definition of the function. */ definition: Fn; - constructor(pointer: PointerValue, definition: Fn); + constructor(pointer: PointerValue, definition: Const<Fn>); /** Call the foreign function. */ call: FromForeignFunction<Fn>; @@ -494,7 +494,7 @@ declare namespace Deno { Definition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition, > { constructor( - definition: Definition, + definition: Const<Definition>, callback: UnsafeCallbackFunction< Definition["parameters"], Definition["result"] @@ -562,6 +562,17 @@ declare namespace Deno { close(): void; } + /** + * This magic code used to implement better type hints for {@linkcode Deno.dlopen} + */ + type Cast<A, B> = A extends B ? A : B; + type Const<T> = Cast< + T, + | (T extends string | number | bigint | boolean ? T : never) + | { [K in keyof T]: Const<T[K]> } + | [] + >; + /** **UNSTABLE**: New API, yet to be vetted. * * Opens an external dynamic library and registers symbols, making foreign @@ -611,7 +622,7 @@ declare namespace Deno { */ export function dlopen<S extends ForeignLibraryInterface>( filename: string | URL, - symbols: S, + symbols: Const<S>, ): DynamicLibrary<S>; /** **UNSTABLE**: New API, yet to be vetted. |