From 46b624954c6eb2a7bfb4648a1e0ec9cd0f1905c8 Mon Sep 17 00:00:00 2001 From: Fluffy Date: Wed, 15 May 2024 16:36:29 +0100 Subject: [PATCH] Switch to tsconfig Fix changes due to change in target module --- front/src/lib/api.ts | 13 +++++-------- front/src/lib/utils.js | 6 ------ front/src/lib/utils.ts | 6 ++++++ front/{jsconfig.json => tsconfig.json} | 8 +++++--- 4 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 front/src/lib/utils.js create mode 100644 front/src/lib/utils.ts rename front/{jsconfig.json => tsconfig.json} (86%) diff --git a/front/src/lib/api.ts b/front/src/lib/api.ts index d21492a..af141a9 100644 --- a/front/src/lib/api.ts +++ b/front/src/lib/api.ts @@ -3,14 +3,11 @@ import { type Item, type JSONResponse } from "./types"; const API_URL = "http://127.0.0.1:8080"; export async function getPopularToday(): Promise { - const response = await fetch(`${API_URL}/api/items`); + const response: Response = await fetch(`${API_URL}/api/items`); const { data, error }: JSONResponse = await response.json(); - if (response.ok) { - if (data?.item) { - return data?.item; - } - throw new Error("Failed to fetch popular today"); - } - throw new Error(error); + if (!response.ok) throw new Error(error); + if (!data?.item) throw new Error("Failed to fetch popular today"); + + return data?.item; } diff --git a/front/src/lib/utils.js b/front/src/lib/utils.js deleted file mode 100644 index 726a1f3..0000000 --- a/front/src/lib/utils.js +++ /dev/null @@ -1,6 +0,0 @@ -export function expandOnTyping(element) { - element.oninput = (event) => { - event.target.style.height = ""; // skipcq: JS-W1032 - event.target.style.height = `${event.target.scrollHeight + 2}px`; - }; -} diff --git a/front/src/lib/utils.ts b/front/src/lib/utils.ts new file mode 100644 index 0000000..92ac3e8 --- /dev/null +++ b/front/src/lib/utils.ts @@ -0,0 +1,6 @@ +export function expandOnTyping(element: HTMLTextAreaElement) { + element.oninput = () => { + element.style.height = ""; // skipcq: JS-W1032 + element.style.height = `${element.scrollHeight + 2}px`; + }; +} diff --git a/front/jsconfig.json b/front/tsconfig.json similarity index 86% rename from front/jsconfig.json rename to front/tsconfig.json index 5696a2d..4953d2b 100644 --- a/front/jsconfig.json +++ b/front/tsconfig.json @@ -1,14 +1,15 @@ { "compilerOptions": { "moduleResolution": "bundler", - "target": "ESNext", - "module": "ESNext", + "module": "ES2015", + "target": "ES2017", + "lib": ["ES2017", "DOM"], /** * svelte-preprocess cannot figure out whether you have * a value or a type, so tell TypeScript to enforce using * `import type` instead of `import` for Types. */ - "verbatimModuleSyntax": true, + "verbatimModuleSyntax": false, "isolatedModules": true, "resolveJsonModule": true, /** @@ -22,6 +23,7 @@ * Typecheck JS in `.svelte` and `.js` files by default. * Disable this if you'd like to use dynamic types. */ + "allowJs": true, "checkJs": true }, /**