From 363580dac22bd015bd0b66bbaa771f3710d05afa Mon Sep 17 00:00:00 2001 From: Michael Zetterberg Date: Thu, 18 Jan 2024 10:45:38 +0100 Subject: [PATCH] feat(WEB-36): improve typings --- app/[lang]/current-content-page/page.tsx | 8 ++++++-- app/[lang]/layout.tsx | 4 ++-- components/Current/Footer/index.tsx | 4 ++-- components/Current/Header/index.tsx | 4 ++-- package.json | 2 +- types/components/current/header.ts | 4 ++-- types/lang.ts | 4 ---- types/params.ts | 23 ++++++++++++++++++++--- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/[lang]/current-content-page/page.tsx b/app/[lang]/current-content-page/page.tsx index 0ceee3782..98eafe533 100644 --- a/app/[lang]/current-content-page/page.tsx +++ b/app/[lang]/current-content-page/page.tsx @@ -4,13 +4,17 @@ import path from "node:path"; import Header from "@/components/Current/Header"; -import type { Params, SearchParams } from "@/types/params"; +import type { PageArgs, LangParams, UriParams } from "@/types/params"; export default async function CurrentContentPage({ params, searchParams, -}: Params) { +}: PageArgs) { try { + if (!searchParams.uri) { + throw new Error("Bad URI"); + } + const filePath = path.join( process.cwd(), "mockCms", diff --git a/app/[lang]/layout.tsx b/app/[lang]/layout.tsx index 5b96d5ec1..1c1c61e7d 100644 --- a/app/[lang]/layout.tsx +++ b/app/[lang]/layout.tsx @@ -7,7 +7,7 @@ import Script from "next/script"; import SkipToMainContent from "@/components/SkipToMainContent"; import type { Metadata } from "next"; -import type { Params } from "@/types/params"; +import type { LangParams, LayoutArgs } from "@/types/params"; export const metadata: Metadata = { description: "New web", @@ -17,7 +17,7 @@ export const metadata: Metadata = { export default function RootLayout({ children, params, -}: React.PropsWithChildren) { +}: React.PropsWithChildren>) { return ( diff --git a/components/Current/Footer/index.tsx b/components/Current/Footer/index.tsx index 4e2e29b17..1fb2ad9d9 100644 --- a/components/Current/Footer/index.tsx +++ b/components/Current/Footer/index.tsx @@ -7,9 +7,9 @@ import Fi from "./Fi"; import No from "./No"; import Sv from "./Sv"; -import type { LangProps } from "@/types/lang"; +import type { LangParams } from "@/types/params"; -export default function Footer({ lang }: LangProps) { +export default function Footer({ lang }: LangParams) { switch (lang) { case langEnum.da: return ; diff --git a/components/Current/Header/index.tsx b/components/Current/Header/index.tsx index 320bae1b5..308627c6e 100644 --- a/components/Current/Header/index.tsx +++ b/components/Current/Header/index.tsx @@ -8,9 +8,9 @@ import No from "./No"; import Sv from "./Sv"; import type { HeaderProps } from "@/types/components/current/header"; -import type { LangProps } from "@/types/lang"; +import { LangParams } from "@/types/params"; -export default function Header({ lang, pathname }: LangProps) { +export default function Header({ lang, pathname }: LangParams & HeaderProps) { switch (lang) { case langEnum.sv: return ; diff --git a/package.json b/package.json index da45b3ffe..42562bd16 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint && tsc" }, "dependencies": { "next": "14.0.4", diff --git a/types/components/current/header.ts b/types/components/current/header.ts index a18f4c2cb..8ff62705b 100644 --- a/types/components/current/header.ts +++ b/types/components/current/header.ts @@ -1,3 +1,3 @@ export type HeaderProps = { - pathname: string -} \ No newline at end of file + pathname: string; +}; diff --git a/types/lang.ts b/types/lang.ts index 0778f58d2..0564e2c6d 100644 --- a/types/lang.ts +++ b/types/lang.ts @@ -8,7 +8,3 @@ export const langEnum = { }; export type Lang = keyof typeof langEnum; - -export type LangProps = T & { - lang: Lang -} \ No newline at end of file diff --git a/types/params.ts b/types/params.ts index 370291661..95aa12197 100644 --- a/types/params.ts +++ b/types/params.ts @@ -1,5 +1,22 @@ -import { Lang } from "./lang"; +import { Lang } from './lang'; -export type Params = T & { params: { lang: Lang } }; +export type SearchParams = { + searchParams: S & { [key: string]: string }; +}; -export type SearchParams = T & { searchParams: { [key: string]: string } }; +export type Params

= { + params: P; +}; + +export type LangParams = { + lang: Lang; +}; + +export type UriParams = { + uri?: string; +}; + +export type LayoutArgs

= P extends undefined ? {} : Params

; + +export type PageArgs

= LayoutArgs

& + (S extends undefined ? {} : SearchParams);