From ea83fa4a68cd04f3a5a73869d878d6b53ba39e2d Mon Sep 17 00:00:00 2001 From: Benny Samir Hierl Date: Fri, 18 Feb 2022 22:17:11 +0100 Subject: [PATCH] typescript issues fixed Signed-off-by: Benny Samir Hierl --- components.d.ts | 2 +- src/App.vue | 4 ++-- src/api/models/wishlist/index.ts | 6 +++++- src/api/routes/utils/opengraph.ts | 7 ++++--- src/components/FormWishlist.vue | 20 ++++++++++---------- src/components/InputFile.vue | 6 +++--- src/composables/useAxios.ts | 2 +- src/composables/useWishlistStore.ts | 11 +++++------ src/views/DetailView.vue | 2 +- src/views/LoginView.vue | 21 ++++++++++----------- 10 files changed, 42 insertions(+), 39 deletions(-) diff --git a/components.d.ts b/components.d.ts index 32eebef..cbe40ef 100644 --- a/components.d.ts +++ b/components.d.ts @@ -35,4 +35,4 @@ declare module 'vue' { } } -export { } +export {} diff --git a/src/App.vue b/src/App.vue index ad49977..c05d64f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -35,9 +35,9 @@ import { onErrorCaptured, ref } from 'vue' import { useI18n } from 'vue-i18n' const { t } = useI18n() -const error = ref(null) +const error = ref() -onErrorCaptured((e: any) => { +onErrorCaptured((e: unknown) => { error.value = e return false }) diff --git a/src/api/models/wishlist/index.ts b/src/api/models/wishlist/index.ts index 7d7dd73..3601965 100644 --- a/src/api/models/wishlist/index.ts +++ b/src/api/models/wishlist/index.ts @@ -1,8 +1,12 @@ import { prisma } from '../../services' import { Wishlist, WishlistItem } from '@/types' +interface WishlistWhereInput { + public?: boolean +} + export default { - getAll: async (where?: any): Promise => { + getAll: async (where?: WishlistWhereInput): Promise => { return (await prisma.client.wishlist.findMany({ where, include: { items: false }, diff --git a/src/api/routes/utils/opengraph.ts b/src/api/routes/utils/opengraph.ts index 36f3519..713e540 100644 --- a/src/api/routes/utils/opengraph.ts +++ b/src/api/routes/utils/opengraph.ts @@ -1,5 +1,5 @@ import { FastifyRequest, FastifyReply, RouteOptions } from 'fastify' -import ogs from 'open-graph-scraper' +import ogs, { OpenGraphImage } from 'open-graph-scraper' interface fetchOpenGraphRequest extends FastifyRequest { query: { @@ -36,8 +36,9 @@ export const fetchOpenGraph = { request.log.debug(result) if (result.success) { const image = - //@ts-expect-error: url not defined - result.ogImage && result.ogImage.url ? result.ogImage.url : '' + result.ogImage && (result.ogImage as OpenGraphImage).url + ? (result.ogImage as OpenGraphImage).url + : '' reply.send({ title: result.ogTitle || '', description: result.ogDescription || '', diff --git a/src/components/FormWishlist.vue b/src/components/FormWishlist.vue index ddeb07a..1047e43 100644 --- a/src/components/FormWishlist.vue +++ b/src/components/FormWishlist.vue @@ -1,10 +1,5 @@ diff --git a/src/components/InputFile.vue b/src/components/InputFile.vue index b5f41b4..4742349 100644 --- a/src/components/InputFile.vue +++ b/src/components/InputFile.vue @@ -108,13 +108,13 @@ const handleFile = async (file: File) => { if (base64String) value.value = base64String } -const handleChange = async (event: any) => { +const handleChange = async (event: Event) => { const file = (event.target as FileEventTarget).files[0] handleFile(file) } -const handleDrop = async (event: any) => { +const handleDrop = async (event: DragEvent) => { showDropzone.value = false - let droppedFiles = event.dataTransfer.files + let droppedFiles = event.dataTransfer?.files if (!droppedFiles) return handleFile(droppedFiles[0]) } diff --git a/src/composables/useAxios.ts b/src/composables/useAxios.ts index d0d0556..4cc5b68 100644 --- a/src/composables/useAxios.ts +++ b/src/composables/useAxios.ts @@ -15,7 +15,7 @@ export interface CustomAxiosError extends AxiosError { const { token } = useAuth() const isLoading = ref(false) -const error = ref(null) +const error = ref(null) const config: AxiosRequestConfig = { baseURL: apiConfig.baseURL, diff --git a/src/composables/useWishlistStore.ts b/src/composables/useWishlistStore.ts index a6fec72..5617e04 100644 --- a/src/composables/useWishlistStore.ts +++ b/src/composables/useWishlistStore.ts @@ -5,8 +5,7 @@ import { useEditMode } from './useEditMode' const { client } = useAxios() const { isActive: editModeIsActive } = useEditMode() -//@ts-expect-error ... -const state = ref({}) +const state = ref() const isReady = ref(false) const fetch = async (slugText: string): Promise => { @@ -14,7 +13,7 @@ const fetch = async (slugText: string): Promise => { const { data } = await client.get(`/wishlist/${slugText}`) state.value = data isReady.value = true - } catch (e: any) { + } catch (e: CustomAxiosError | any) { if (e.isAxiosError && !(e.ignore)) { throw e } @@ -33,7 +32,7 @@ const update = async (updatedData: Wishlist): Promise => { ...state.value, ...data, } - } catch (e: any) { + } catch (e: CustomAxiosError | any) { if (e.isAxiosError && !(e.ignore)) { throw e } @@ -48,7 +47,7 @@ const createItem = async (values: WishlistItem): Promise => { try { const { data } = await client.post(`/wishlist/${id}/item`, payload) state.value?.items?.push(data) - } catch (e: any) { + } catch (e: CustomAxiosError | any) { if (e.isAxiosError && !(e.ignore)) { throw e } @@ -74,7 +73,7 @@ const updateItem = async ( 1, data ) - } catch (e: any) { + } catch (e: CustomAxiosError | any) { if (e.isAxiosError && !(e.ignore)) { throw e } diff --git a/src/views/DetailView.vue b/src/views/DetailView.vue index 401c76b..34dc3fc 100644 --- a/src/views/DetailView.vue +++ b/src/views/DetailView.vue @@ -26,7 +26,7 @@ const { } = useWishlistStore() const title = computed(() => { - return state.value.title + return state.value?.title ? t('common.title.text', { title: state.value.title }) : t('common.loading.text') }) diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index ea3299d..333f9c9 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -1,7 +1,7 @@