From a2e9f5ef6f9e2726500796159347dc9eb578eb0d Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Wed, 2 Jul 2025 23:49:36 +0200 Subject: [PATCH] fix types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Petter Sæterøy --- src/components/About.astro | 4 ++-- src/components/FAQ.astro | 4 ++-- src/components/Footer.astro | 4 ++-- src/components/Hero.astro | 4 ++-- src/components/Nav.astro | 7 +++---- src/components/Program.astro | 16 ++++++++++++---- src/components/Vors.astro | 4 ++-- src/data/{i18n.js => i18n.ts} | 4 +++- 8 files changed, 28 insertions(+), 19 deletions(-) rename src/data/{i18n.js => i18n.ts} (98%) diff --git a/src/components/About.astro b/src/components/About.astro index 0f9fc5a..2b90f5b 100644 --- a/src/components/About.astro +++ b/src/components/About.astro @@ -1,8 +1,8 @@ --- -import { translations } from '@data/i18n.js'; +import { translations, type Lang } from '@data/i18n'; import { Image } from 'astro:assets'; import benker from '@assets/studioBenker.png'; -const { lang = 'no' } = Astro.props; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].about; --- diff --git a/src/components/FAQ.astro b/src/components/FAQ.astro index 5f1f0d9..906eae5 100644 --- a/src/components/FAQ.astro +++ b/src/components/FAQ.astro @@ -1,6 +1,6 @@ --- -import { translations } from '@data/i18n.js'; -const { lang = 'no' } = Astro.props; +import { translations, type Lang } from '@data/i18n'; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].faq; --- diff --git a/src/components/Footer.astro b/src/components/Footer.astro index fb63986..c29d811 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -2,9 +2,9 @@ import { Image } from 'astro:assets'; import logo from '@assets/logo.png'; import DNS from '@assets/DNS-logo-hvit.png'; -import { translations } from '@data/i18n.js'; +import { translations, type Lang } from '@data/i18n'; import Links from '@components/Links.astro'; -const { lang = 'no' } = Astro.props; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].footer; --- diff --git a/src/components/Hero.astro b/src/components/Hero.astro index 54769bf..e018644 100644 --- a/src/components/Hero.astro +++ b/src/components/Hero.astro @@ -1,8 +1,8 @@ --- import logo from '@assets/logo.png'; import { Image } from 'astro:assets'; -import { translations } from '@data/i18n.js'; -const { lang = 'no' } = Astro.props; +import { translations, type Lang } from '@data/i18n'; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].hero; --- diff --git a/src/components/Nav.astro b/src/components/Nav.astro index 8d7e4c2..6f38e70 100644 --- a/src/components/Nav.astro +++ b/src/components/Nav.astro @@ -1,12 +1,11 @@ --- import NavLink from '@components/NavLink.astro'; - -import { translations } from '@data/i18n.js'; -const { lang = 'no' } = Astro.props; +import { translations, type Lang } from '@data/i18n'; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].nav; const { pathname } = Astro.url; -function getLangSwitchPath(path, lang) { +function getLangSwitchPath(path: string, lang: string) { if (lang === 'no') { if (path === '/') return '/en/'; if (path.startsWith('/en/')) return path.replace('/en/', '/'); diff --git a/src/components/Program.astro b/src/components/Program.astro index b5f1d92..9c345af 100644 --- a/src/components/Program.astro +++ b/src/components/Program.astro @@ -1,9 +1,17 @@ --- -import { translations } from '@data/i18n.js'; -const { lang = 'no', data } = Astro.props; +import { translations, type Lang } from '@data/i18n'; +const { lang = 'no', data } = Astro.props as { lang?: Lang, data: any }; const t = translations[lang].program; -const convertDate = (date) => { +type ProgramItem = { + time: string; + event: string; + price?: string | null; + cost?: string | null; + url?: string; +}; + +const convertDate = (date: string | Date) => { let d = date; if (!(d instanceof Date)) { d = new Date(d); @@ -26,7 +34,7 @@ const convertDate = (date) => {

{convertDate(date)}

    - {items.map((item) => { + {(items as ProgramItem[]).map((item) => { const price = item.price || item.cost; return (
  • diff --git a/src/components/Vors.astro b/src/components/Vors.astro index 6c831ff..3bb22bc 100644 --- a/src/components/Vors.astro +++ b/src/components/Vors.astro @@ -1,6 +1,6 @@ --- -import { translations } from '@data/i18n.js'; -const { lang = 'no' } = Astro.props; +import { translations, type Lang } from '@data/i18n'; +const { lang = 'no' } = Astro.props as { lang?: Lang }; const t = translations[lang].vors; const videoUrl = "https://www.youtube.com/watch?v=t7T4RPBpTVY"; diff --git a/src/data/i18n.js b/src/data/i18n.ts similarity index 98% rename from src/data/i18n.js rename to src/data/i18n.ts index 3a7b8af..9cf767f 100644 --- a/src/data/i18n.js +++ b/src/data/i18n.ts @@ -93,4 +93,6 @@ export const translations = { dnsAlt: "Logo for the Norwegian Student Society", }, }, -}; +} as const; + +export type Lang = keyof typeof translations;