From ac603ac18eeab598159371d8c46d095a1b3555fc Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 30 Dec 2023 15:13:24 +0100 Subject: [PATCH] fix(frontend): fix type errors --- frontend/src/app.d.ts | 25 +++---------------- .../src/routes/@[username]/+page.server.ts | 2 +- .../@[username]/[memberName]/+page.server.ts | 4 +-- .../@[username]/[memberName]/edit/+layout.ts | 5 ++-- .../src/routes/@[username]/edit/+layout.ts | 5 ++-- .../src/routes/[username]/+page.server.ts | 2 +- frontend/src/routes/edit/member/[id]/+page.ts | 2 +- frontend/src/routes/edit/profile/+page.ts | 2 +- frontend/src/routes/page/about/+page.svelte | 1 + .../src/routes/page/changelog/+page.svelte | 1 + frontend/src/routes/page/privacy/+page.svelte | 1 + frontend/src/routes/page/terms/+page.svelte | 1 + .../pronouns/[...pronouns]/+page.svelte | 2 +- frontend/src/routes/settings/export/+page.ts | 2 +- frontend/src/svelte-hcaptcha.d.ts | 18 +++++++++++++ 15 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 frontend/src/svelte-hcaptcha.d.ts diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index ba59572..9489da5 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -1,38 +1,19 @@ // See https://kit.svelte.dev/docs/types#app -import type { APIError, ErrorCode } from "$lib/api/entities"; +import type { ErrorCode } from "$lib/api/entities"; // for information about these interfaces declare global { namespace App { - type Error = { + interface Error { code: ErrorCode; message?: string | undefined; details?: string | undefined; - } | APIError + } // interface Locals {} // interface PageData {} // interface Platform {} } } -declare module "svelte-hcaptcha" { - import type { SvelteComponent } from "svelte"; - - export interface HCaptchaProps { - sitekey?: string; - apihost?: string; - hl?: string; - reCaptchaCompat?: boolean; - theme?: CaptchaTheme; - size?: string; - } - - declare class HCaptcha extends SvelteComponent { - $$prop_def: HCaptchaProps; - } - - export default HCaptcha; -} - export {}; diff --git a/frontend/src/routes/@[username]/+page.server.ts b/frontend/src/routes/@[username]/+page.server.ts index 1e7b8af..0ae4617 100644 --- a/frontend/src/routes/@[username]/+page.server.ts +++ b/frontend/src/routes/@[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { return resp; } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - error(404, e as APIError); + error(404, e as App.Error); } throw e; diff --git a/frontend/src/routes/@[username]/[memberName]/+page.server.ts b/frontend/src/routes/@[username]/[memberName]/+page.server.ts index ad5925d..02aff1b 100644 --- a/frontend/src/routes/@[username]/[memberName]/+page.server.ts +++ b/frontend/src/routes/@[username]/[memberName]/+page.server.ts @@ -14,9 +14,9 @@ export const load = async ({ params }) => { (e as APIError).code === ErrorCode.UserNotFound || (e as APIError).code === ErrorCode.MemberNotFound ) { - error(404, e as APIError); + error(404, e as App.Error); } - error(500, e as APIError); + error(500, e as App.Error); } }; diff --git a/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts index e6333c0..8493fa6 100644 --- a/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts +++ b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts @@ -41,8 +41,9 @@ export const load = (async ({ params }) => { pronouns: pronouns.autocomplete, flags, }; - } catch (e) { - if ("code" in e) error(500, e as APIError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + if ("code" in e) error(500, e as App.Error); throw e; } }) satisfies LayoutLoad; diff --git a/frontend/src/routes/@[username]/edit/+layout.ts b/frontend/src/routes/@[username]/edit/+layout.ts index de77441..23e176d 100644 --- a/frontend/src/routes/@[username]/edit/+layout.ts +++ b/frontend/src/routes/@[username]/edit/+layout.ts @@ -21,8 +21,9 @@ export const load = async ({ params }) => { pronouns: pronouns.autocomplete, flags, }; - } catch (e) { - if ("code" in e) error(500, e as APIError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + if ("code" in e) error(500, e as App.Error); throw e; } }; diff --git a/frontend/src/routes/[username]/+page.server.ts b/frontend/src/routes/[username]/+page.server.ts index b291ccb..6784dee 100644 --- a/frontend/src/routes/[username]/+page.server.ts +++ b/frontend/src/routes/[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { redirect(303, `/@${resp.name}`); } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - error(404, e as APIError); + error(404, e as App.Error); } throw e; diff --git a/frontend/src/routes/edit/member/[id]/+page.ts b/frontend/src/routes/edit/member/[id]/+page.ts index 96a64a2..1d6132c 100644 --- a/frontend/src/routes/edit/member/[id]/+page.ts +++ b/frontend/src/routes/edit/member/[id]/+page.ts @@ -23,7 +23,7 @@ export const load = async ({ params }) => { (e as APIError).code === ErrorCode.InvalidToken || (e as APIError).code === ErrorCode.NotOwnMember ) { - error(403, e as APIError); + error(403, e as App.Error); } throw e; diff --git a/frontend/src/routes/edit/profile/+page.ts b/frontend/src/routes/edit/profile/+page.ts index 71cd278..085adf3 100644 --- a/frontend/src/routes/edit/profile/+page.ts +++ b/frontend/src/routes/edit/profile/+page.ts @@ -14,7 +14,7 @@ export const load = async () => { (e as APIError).code === ErrorCode.Forbidden || (e as APIError).code === ErrorCode.InvalidToken ) { - error(403, e as APIError); + error(403, e as App.Error); } throw e; diff --git a/frontend/src/routes/page/about/+page.svelte b/frontend/src/routes/page/about/+page.svelte index ea19018..82fb6eb 100644 --- a/frontend/src/routes/page/about/+page.svelte +++ b/frontend/src/routes/page/about/+page.svelte @@ -1,4 +1,5 @@ diff --git a/frontend/src/routes/page/changelog/+page.svelte b/frontend/src/routes/page/changelog/+page.svelte index 51cc848..890f472 100644 --- a/frontend/src/routes/page/changelog/+page.svelte +++ b/frontend/src/routes/page/changelog/+page.svelte @@ -1,5 +1,6 @@ diff --git a/frontend/src/routes/page/terms/+page.svelte b/frontend/src/routes/page/terms/+page.svelte index ea126d0..fc3734e 100644 --- a/frontend/src/routes/page/terms/+page.svelte +++ b/frontend/src/routes/page/terms/+page.svelte @@ -1,4 +1,5 @@ diff --git a/frontend/src/routes/pronouns/[...pronouns]/+page.svelte b/frontend/src/routes/pronouns/[...pronouns]/+page.svelte index fd9536f..09a4329 100644 --- a/frontend/src/routes/pronouns/[...pronouns]/+page.svelte +++ b/frontend/src/routes/pronouns/[...pronouns]/+page.svelte @@ -1,6 +1,6 @@