From 9807f76affce7cca08cc788df80c09b53292fac0 Mon Sep 17 00:00:00 2001
From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
Date: Fri, 2 Jun 2023 15:55:08 +0200
Subject: [PATCH] chore(web): improve type checking (#2644)
* fix(web): use id instead of assetId
* chore(web): improve type checking
* fix test jobs
* improve type checking and resolve errors
---
.github/workflows/test.yml | 6 +++-
web/package.json | 7 +++--
web/src/api/utils.ts | 4 +--
web/src/hooks.server.ts | 4 +--
.../admin-page/jobs/jobs-panel.svelte | 4 +--
.../server-stats/server-stats-panel.svelte | 12 ++++----
.../supported-datetime-panel.svelte | 2 +-
.../album-page/__tests__/album-card.spec.ts | 12 ++++----
.../components/album-page/album-card.svelte | 18 ++---------
.../lib/components/album-page/album-card.ts | 12 ++++++++
.../album-page/asset-selection.svelte | 14 ++++-----
.../album-page/thumbnail-selection.svelte | 4 +--
.../asset-viewer/asset-viewer-nav-bar.svelte | 22 +++++++-------
.../lib/components/forms/api-key-form.svelte | 4 +--
.../map-page/map-settings-modal.svelte | 11 +------
.../photos-page/asset-date-group.svelte | 14 ++++-----
.../components/photos-page/asset-grid.svelte | 17 +++++------
.../asset-select-control-bar.svelte | 2 +-
.../create-shared-link-modal.svelte | 30 +++++++++----------
.../asset-marker-cluster.svelte | 2 +-
.../navigation-bar/account-info-panel.svelte | 8 ++---
.../upload-asset-preview.svelte | 8 ++---
.../user-settings-page/device-card.svelte | 2 +-
web/src/lib/models/asset-grid-state.ts | 2 +-
web/src/lib/stores/archived-asset.store.ts | 2 +-
web/src/lib/stores/preferences.store.ts | 9 +++++-
web/src/lib/utils/file-uploader.ts | 12 ++++----
web/src/lib/utils/handle-error.ts | 2 +-
web/src/routes/(user)/albums/albums.bloc.ts | 4 +--
web/src/routes/(user)/search/+page.svelte | 2 +-
web/src/test-data/factories/album-factory.ts | 7 +++--
web/src/test-data/factories/user-factory.ts | 18 +++++++++++
web/tsconfig.json | 1 -
33 files changed, 149 insertions(+), 129 deletions(-)
create mode 100644 web/src/lib/components/album-page/album-card.ts
create mode 100644 web/src/test-data/factories/user-factory.ts
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index ef9dc8ada..98da1a783 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -96,7 +96,11 @@ jobs:
if: ${{ !cancelled() }}
- name: Run svelte checks
- run: npm run check
+ run: npm run check:svelte
+ if: ${{ !cancelled() }}
+
+ - name: Run tsc
+ run: npm run check:typescript
if: ${{ !cancelled() }}
- name: Run unit tests & coverage
diff --git a/web/package.json b/web/package.json
index 90673a3a3..09df801a1 100644
--- a/web/package.json
+++ b/web/package.json
@@ -6,9 +6,10 @@
"build": "vite build",
"package": "svelte-kit package",
"preview": "vite preview",
- "check": "svelte-check --no-tsconfig --fail-on-warnings --ignore \"src/api/open-api\"",
- "check:watch": "npm run check -- --watch",
- "check:code": "npm run format && npm run lint && npm run check",
+ "check:svelte": "svelte-check --no-tsconfig --fail-on-warnings --ignore \"src/api/open-api\"",
+ "check:typescript": "tsc --noEmit",
+ "check:watch": "npm run check:svelte -- --watch",
+ "check:code": "npm run format && npm run lint && npm run check:svelte && npm run check:typescript",
"check:all": "npm run check:code && npm run test:cov",
"lint": "eslint . --max-warnings 0",
"lint:fix": "npm run lint -- --fix",
diff --git a/web/src/api/utils.ts b/web/src/api/utils.ts
index c7fa62bfa..39c319901 100644
--- a/web/src/api/utils.ts
+++ b/web/src/api/utils.ts
@@ -1,6 +1,6 @@
-import { AxiosError, AxiosPromise } from 'axios';
+import type { AxiosError, AxiosPromise } from 'axios';
import { api } from './api';
-import { UserResponseDto } from './open-api';
+import type { UserResponseDto } from './open-api';
export type ApiError = AxiosError<{ message: string }>;
diff --git a/web/src/hooks.server.ts b/web/src/hooks.server.ts
index 959ed5e3e..8998257e7 100644
--- a/web/src/hooks.server.ts
+++ b/web/src/hooks.server.ts
@@ -1,6 +1,6 @@
-import type { Handle, HandleServerError } from '@sveltejs/kit';
-import { AxiosError, AxiosResponse } from 'axios';
import { env } from '$env/dynamic/public';
+import type { Handle, HandleServerError } from '@sveltejs/kit';
+import type { AxiosError, AxiosResponse } from 'axios';
import { ImmichApi } from './api/api';
export const handle = (async ({ event, resolve }) => {
diff --git a/web/src/lib/components/admin-page/jobs/jobs-panel.svelte b/web/src/lib/components/admin-page/jobs/jobs-panel.svelte
index 06a3d05a5..5930cfa41 100644
--- a/web/src/lib/components/admin-page/jobs/jobs-panel.svelte
+++ b/web/src/lib/components/admin-page/jobs/jobs-panel.svelte
@@ -3,10 +3,11 @@
notificationController,
NotificationType
} from '$lib/components/shared-components/notification/notification';
+ import { AppRoute } from '$lib/constants';
import { handleError } from '$lib/utils/handle-error';
import { AllJobStatusResponseDto, api, JobCommand, JobCommandDto, JobName } from '@api';
import type { ComponentType } from 'svelte';
- import Icon from 'svelte-material-icons/DotsVertical.svelte';
+ import type Icon from 'svelte-material-icons/DotsVertical.svelte';
import FaceRecognition from 'svelte-material-icons/FaceRecognition.svelte';
import FileJpgBox from 'svelte-material-icons/FileJpgBox.svelte';
import FileXmlBox from 'svelte-material-icons/FileXmlBox.svelte';
@@ -19,7 +20,6 @@
import ConfirmDialogue from '../../shared-components/confirm-dialogue.svelte';
import JobTile from './job-tile.svelte';
import StorageMigrationDescription from './storage-migration-description.svelte';
- import { AppRoute } from '$lib/constants';
export let jobs: AllJobStatusResponseDto;
diff --git a/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte b/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte
index c1b73f9a4..c1d26f115 100644
--- a/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte
+++ b/web/src/lib/components/admin-page/server-stats/server-stats-panel.svelte
@@ -1,11 +1,11 @@
-
-