typescript issues fixed

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2022-02-18 22:17:11 +01:00
parent afc246f0b3
commit ea83fa4a68
10 changed files with 42 additions and 39 deletions

2
components.d.ts vendored
View file

@ -35,4 +35,4 @@ declare module 'vue' {
} }
} }
export { } export {}

View file

@ -35,9 +35,9 @@ import { onErrorCaptured, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
const { t } = useI18n() const { t } = useI18n()
const error = ref(null) const error = ref()
onErrorCaptured((e: any) => { onErrorCaptured((e: unknown) => {
error.value = e error.value = e
return false return false
}) })

View file

@ -1,8 +1,12 @@
import { prisma } from '../../services' import { prisma } from '../../services'
import { Wishlist, WishlistItem } from '@/types' import { Wishlist, WishlistItem } from '@/types'
interface WishlistWhereInput {
public?: boolean
}
export default { export default {
getAll: async (where?: any): Promise<Wishlist[]> => { getAll: async (where?: WishlistWhereInput): Promise<Wishlist[]> => {
return (await prisma.client.wishlist.findMany({ return (await prisma.client.wishlist.findMany({
where, where,
include: { items: false }, include: { items: false },

View file

@ -1,5 +1,5 @@
import { FastifyRequest, FastifyReply, RouteOptions } from 'fastify' import { FastifyRequest, FastifyReply, RouteOptions } from 'fastify'
import ogs from 'open-graph-scraper' import ogs, { OpenGraphImage } from 'open-graph-scraper'
interface fetchOpenGraphRequest extends FastifyRequest { interface fetchOpenGraphRequest extends FastifyRequest {
query: { query: {
@ -36,8 +36,9 @@ export const fetchOpenGraph = <RouteOptions>{
request.log.debug(result) request.log.debug(result)
if (result.success) { if (result.success) {
const image = const image =
//@ts-expect-error: url not defined result.ogImage && (result.ogImage as OpenGraphImage).url
result.ogImage && result.ogImage.url ? result.ogImage.url : '' ? (result.ogImage as OpenGraphImage).url
: ''
reply.send({ reply.send({
title: result.ogTitle || '', title: result.ogTitle || '',
description: result.ogDescription || '', description: result.ogDescription || '',

View file

@ -1,10 +1,5 @@
<template> <template>
<Form <form @submit="onSubmit" class="w-full flex-col">
@submit="onSubmit"
:validation-schema="schema"
v-slot="{ meta }"
class="w-full flex-col"
>
<InputText <InputText
name="title" name="title"
type="text" type="text"
@ -46,13 +41,13 @@
:icon="IconSave" :icon="IconSave"
>{{ t('components.form-wishlist.submit.text') }}</ButtonBase >{{ t('components.form-wishlist.submit.text') }}</ButtonBase
> >
</Form> </form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Wishlist } from '@/types' import { Wishlist } from '@/types'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { Form } from 'vee-validate' import { useForm } from 'vee-validate'
import IconSave from '@/components/icons/IconSave.vue' import IconSave from '@/components/icons/IconSave.vue'
import { object, string, boolean } from 'yup' import { object, string, boolean } from 'yup'
@ -94,8 +89,13 @@ const schema = object().shape(
['imageSrc', 'imageFile'] ['imageSrc', 'imageFile']
) )
const onSubmit = async (values: any): Promise<void> => { const { handleSubmit, meta } = useForm({
//@ts-expect-error ...
validationSchema: schema,
})
const onSubmit = handleSubmit((values) => {
values.imageSrc = values.imageFile || values.imageSrc values.imageSrc = values.imageFile || values.imageSrc
emits('update', values) emits('update', values)
} })
</script> </script>

View file

@ -108,13 +108,13 @@ const handleFile = async (file: File) => {
if (base64String) value.value = base64String if (base64String) value.value = base64String
} }
const handleChange = async (event: any) => { const handleChange = async (event: Event) => {
const file = (event.target as FileEventTarget).files[0] const file = (event.target as FileEventTarget).files[0]
handleFile(file) handleFile(file)
} }
const handleDrop = async (event: any) => { const handleDrop = async (event: DragEvent) => {
showDropzone.value = false showDropzone.value = false
let droppedFiles = event.dataTransfer.files let droppedFiles = event.dataTransfer?.files
if (!droppedFiles) return if (!droppedFiles) return
handleFile(droppedFiles[0]) handleFile(droppedFiles[0])
} }

View file

@ -15,7 +15,7 @@ export interface CustomAxiosError extends AxiosError {
const { token } = useAuth() const { token } = useAuth()
const isLoading = ref(false) const isLoading = ref(false)
const error = ref<any | null>(null) const error = ref<CustomAxiosError | null>(null)
const config: AxiosRequestConfig = { const config: AxiosRequestConfig = {
baseURL: apiConfig.baseURL, baseURL: apiConfig.baseURL,

View file

@ -5,8 +5,7 @@ import { useEditMode } from './useEditMode'
const { client } = useAxios() const { client } = useAxios()
const { isActive: editModeIsActive } = useEditMode() const { isActive: editModeIsActive } = useEditMode()
//@ts-expect-error ... const state = ref<Wishlist>()
const state = ref<Wishlist>({})
const isReady = ref(false) const isReady = ref(false)
const fetch = async (slugText: string): Promise<void> => { const fetch = async (slugText: string): Promise<void> => {
@ -14,7 +13,7 @@ const fetch = async (slugText: string): Promise<void> => {
const { data } = await client.get(`/wishlist/${slugText}`) const { data } = await client.get(`/wishlist/${slugText}`)
state.value = data state.value = data
isReady.value = true isReady.value = true
} catch (e: any) { } catch (e: CustomAxiosError | any) {
if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) { if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) {
throw e throw e
} }
@ -33,7 +32,7 @@ const update = async (updatedData: Wishlist): Promise<void> => {
...state.value, ...state.value,
...data, ...data,
} }
} catch (e: any) { } catch (e: CustomAxiosError | any) {
if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) { if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) {
throw e throw e
} }
@ -48,7 +47,7 @@ const createItem = async (values: WishlistItem): Promise<void> => {
try { try {
const { data } = await client.post(`/wishlist/${id}/item`, payload) const { data } = await client.post(`/wishlist/${id}/item`, payload)
state.value?.items?.push(data) state.value?.items?.push(data)
} catch (e: any) { } catch (e: CustomAxiosError | any) {
if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) { if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) {
throw e throw e
} }
@ -74,7 +73,7 @@ const updateItem = async (
1, 1,
data data
) )
} catch (e: any) { } catch (e: CustomAxiosError | any) {
if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) { if (e.isAxiosError && !(<CustomAxiosError>e.ignore)) {
throw e throw e
} }

View file

@ -26,7 +26,7 @@ const {
} = useWishlistStore() } = useWishlistStore()
const title = computed(() => { const title = computed(() => {
return state.value.title return state.value?.title
? t('common.title.text', { title: state.value.title }) ? t('common.title.text', { title: state.value.title })
: t('common.loading.text') : t('common.loading.text')
}) })

View file

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { Form } from 'vee-validate' import { useForm } from 'vee-validate'
import { object, string } from 'yup' import { object, string } from 'yup'
import { useAuth } from '@/composables' import { useAuth } from '@/composables'
import IconLogin from '@/components/icons/IconLogin.vue' import IconLogin from '@/components/icons/IconLogin.vue'
@ -17,10 +17,14 @@ const schema = object({
), ),
}) })
const onSubmit = (values: any): void => { const { handleSubmit, meta } = useForm({
setToken(values['api-key']) validationSchema: schema,
})
const onSubmit = handleSubmit((values) => {
setToken(values['api-key'] as string)
router.push('/') router.push('/')
} })
</script> </script>
<template> <template>
@ -31,12 +35,7 @@ const onSubmit = (values: any): void => {
<h1 class="text-semibold mb-8 text-center text-3xl"> <h1 class="text-semibold mb-8 text-center text-3xl">
{{ t('pages.login-view.main.title.text') }} {{ t('pages.login-view.main.title.text') }}
</h1> </h1>
<Form <form @submit="onSubmit" class="w-full flex-col space-y-3">
@submit="onSubmit"
:validation-schema="schema"
v-slot="{ meta }"
class="w-full flex-col space-y-3"
>
<InputText <InputText
name="api-key" name="api-key"
type="text" type="text"
@ -50,7 +49,7 @@ const onSubmit = (values: any): void => {
:disabled="!meta.dirty || !meta.valid" :disabled="!meta.dirty || !meta.valid"
>{{ t('pages.login-view.main.form.submit.text') }}</ButtonBase >{{ t('pages.login-view.main.form.submit.text') }}</ButtonBase
> >
</Form> </form>
</div> </div>
</div> </div>
</template> </template>