fix(frontend): fix type errors

This commit is contained in:
sam 2023-12-30 15:13:24 +01:00
parent 00abe1cb32
commit ac603ac18e
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
15 changed files with 39 additions and 34 deletions

25
frontend/src/app.d.ts vendored
View File

@ -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 {};

View File

@ -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;

View File

@ -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);
}
};

View File

@ -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;

View File

@ -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;
}
};

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,5 @@
<script lang="ts">
//@ts-ignore
import { html } from "./about.md";
</script>

View File

@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
//@ts-ignore
import { html } from "./changelog.md";
import { CURRENT_CHANGELOG } from "$lib/store";

View File

@ -1,4 +1,5 @@
<script lang="ts">
//@ts-ignore
import { html } from "./privacy.md";
</script>

View File

@ -1,4 +1,5 @@
<script lang="ts">
//@ts-ignore
import { html } from "./terms.md";
</script>

View File

@ -1,6 +1,6 @@
<script lang="ts">
import { PUBLIC_BASE_URL } from "$env/static/public";
import type { PageData } from "../../$types";
import type { PageData } from "./$types";
export let data: PageData;

View File

@ -10,6 +10,6 @@ export const load = async () => {
} catch (e) {
if ((e as APIError).code === ErrorCode.NotFound) return { exportData: null };
error(500, e as APIError);
error(500, e as App.Error);
}
};

18
frontend/src/svelte-hcaptcha.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
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;
}