mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
Refactor type definitions in hydra-api.ts to replace any
with unknown
- Replaced instances of `any` with `unknown` in the `get`, `post`, `put`, `patch`, and `delete` methods for safer type handling. - Updated parameters like `data` and `params` to use `Record<string, unknown>` for better type safety. - Improved overall type robustness and eliminated warnings related to the use of `any`. Contributed by: [Jonhvmp](https://github.com/Jonhvmp)
This commit is contained in:
parent
c7f2a861d5
commit
a09124e8be
@ -2,12 +2,12 @@ import { ipcMain } from "electron";
|
|||||||
|
|
||||||
export const registerEvent = (
|
export const registerEvent = (
|
||||||
name: string,
|
name: string,
|
||||||
listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any
|
listener: (event: Electron.IpcMainInvokeEvent, ...args: unknown[]) => unknown
|
||||||
) => {
|
) => {
|
||||||
ipcMain.handle(name, async (event: Electron.IpcMainInvokeEvent, ...args) => {
|
ipcMain.handle(name, async (event: Electron.IpcMainInvokeEvent, ...args: unknown[]) => {
|
||||||
return Promise.resolve(listener(event, ...args)).then((result) => {
|
return Promise.resolve(listener(event, ...args)).then((result) => {
|
||||||
if (!result) return result;
|
if (!result) return result;
|
||||||
return JSON.parse(JSON.stringify(result));
|
return JSON.parse(JSON.stringify(result)); // Garante que o objeto é serializável
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -227,9 +227,9 @@ export class HydraApi {
|
|||||||
throw err;
|
throw err;
|
||||||
};
|
};
|
||||||
|
|
||||||
static async get<T = any>(
|
static async get<T = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
params?: any,
|
params?: Record<string, unknown>,
|
||||||
options?: HydraApiOptions
|
options?: HydraApiOptions
|
||||||
) {
|
) {
|
||||||
if (!options || options.needsAuth) {
|
if (!options || options.needsAuth) {
|
||||||
@ -243,9 +243,9 @@ export class HydraApi {
|
|||||||
.catch(this.handleUnauthorizedError);
|
.catch(this.handleUnauthorizedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async post<T = any>(
|
static async post<T = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: any,
|
data?: Record<string, unknown>,
|
||||||
options?: HydraApiOptions
|
options?: HydraApiOptions
|
||||||
) {
|
) {
|
||||||
if (!options || options.needsAuth) {
|
if (!options || options.needsAuth) {
|
||||||
@ -259,9 +259,9 @@ export class HydraApi {
|
|||||||
.catch(this.handleUnauthorizedError);
|
.catch(this.handleUnauthorizedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async put<T = any>(
|
static async put<T = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: any,
|
data?: Record<string, unknown>,
|
||||||
options?: HydraApiOptions
|
options?: HydraApiOptions
|
||||||
) {
|
) {
|
||||||
if (!options || options.needsAuth) {
|
if (!options || options.needsAuth) {
|
||||||
@ -275,9 +275,9 @@ export class HydraApi {
|
|||||||
.catch(this.handleUnauthorizedError);
|
.catch(this.handleUnauthorizedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async patch<T = any>(
|
static async patch<T = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: any,
|
data?: Record<string, unknown>,
|
||||||
options?: HydraApiOptions
|
options?: HydraApiOptions
|
||||||
) {
|
) {
|
||||||
if (!options || options.needsAuth) {
|
if (!options || options.needsAuth) {
|
||||||
@ -291,7 +291,7 @@ export class HydraApi {
|
|||||||
.catch(this.handleUnauthorizedError);
|
.catch(this.handleUnauthorizedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async delete<T = any>(url: string, options?: HydraApiOptions) {
|
static async delete<T = unknown>(url: string, options?: HydraApiOptions) {
|
||||||
if (!options || options.needsAuth) {
|
if (!options || options.needsAuth) {
|
||||||
if (!this.isLoggedIn()) throw new UserNotLoggedInError();
|
if (!this.isLoggedIn()) throw new UserNotLoggedInError();
|
||||||
await this.revalidateAccessTokenIfExpired();
|
await this.revalidateAccessTokenIfExpired();
|
||||||
|
Loading…
Reference in New Issue
Block a user