fix(api.js): Change cb type in mockIPC to return unknown (#11724)

This commit is contained in:
Fabian-Lars 2024-11-18 16:50:39 +01:00 committed by GitHub
parent f2814ed538
commit b63262cd4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"@tauri-apps/api": "patch:bug"
---
Removed the generic in the type of the callback function argument in `mockIPC` which prevented its proper use in tests using TypeScript.

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { InvokeArgs, InvokeOptions } from './core'
import type { invoke, InvokeArgs, InvokeOptions } from './core'
function mockInternals() {
window.__TAURI_INTERNALS__ = window.__TAURI_INTERNALS__ ?? {}
@ -62,7 +62,7 @@ function mockInternals() {
* @since 1.0.0
*/
export function mockIPC(
cb: <T>(cmd: string, payload?: InvokeArgs) => Promise<T>
cb: (cmd: string, payload?: InvokeArgs) => unknown
): void {
mockInternals()
@ -90,14 +90,15 @@ export function mockIPC(
return identifier
}
window.__TAURI_INTERNALS__.invoke = function <T>(
// eslint-disable-next-line @typescript-eslint/require-await
window.__TAURI_INTERNALS__.invoke = async function (
cmd: string,
args?: InvokeArgs,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: InvokeOptions
): Promise<T> {
): Promise<unknown> {
return cb(cmd, args)
}
} as typeof invoke
}
/**