feat(WEB-36): improve typings

This commit is contained in:
Michael Zetterberg
2024-01-18 10:45:38 +01:00
parent 39b61c7691
commit 363580dac2
8 changed files with 35 additions and 18 deletions

View File

@@ -4,13 +4,17 @@ import path from "node:path";
import Header from "@/components/Current/Header"; 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({ export default async function CurrentContentPage({
params, params,
searchParams, searchParams,
}: Params<SearchParams>) { }: PageArgs<LangParams, UriParams>) {
try { try {
if (!searchParams.uri) {
throw new Error("Bad URI");
}
const filePath = path.join( const filePath = path.join(
process.cwd(), process.cwd(),
"mockCms", "mockCms",

View File

@@ -7,7 +7,7 @@ import Script from "next/script";
import SkipToMainContent from "@/components/SkipToMainContent"; import SkipToMainContent from "@/components/SkipToMainContent";
import type { Metadata } from "next"; import type { Metadata } from "next";
import type { Params } from "@/types/params"; import type { LangParams, LayoutArgs } from "@/types/params";
export const metadata: Metadata = { export const metadata: Metadata = {
description: "New web", description: "New web",
@@ -17,7 +17,7 @@ export const metadata: Metadata = {
export default function RootLayout({ export default function RootLayout({
children, children,
params, params,
}: React.PropsWithChildren<Params>) { }: React.PropsWithChildren<LayoutArgs<LangParams>>) {
return ( return (
<html lang={params.lang}> <html lang={params.lang}>
<head> <head>

View File

@@ -7,9 +7,9 @@ import Fi from "./Fi";
import No from "./No"; import No from "./No";
import Sv from "./Sv"; 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) { switch (lang) {
case langEnum.da: case langEnum.da:
return <Da />; return <Da />;

View File

@@ -8,9 +8,9 @@ import No from "./No";
import Sv from "./Sv"; import Sv from "./Sv";
import type { HeaderProps } from "@/types/components/current/header"; 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<HeaderProps>) { export default function Header({ lang, pathname }: LangParams & HeaderProps) {
switch (lang) { switch (lang) {
case langEnum.sv: case langEnum.sv:
return <Sv pathname={pathname} />; return <Sv pathname={pathname} />;

View File

@@ -6,7 +6,7 @@
"dev": "next dev", "dev": "next dev",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint" "lint": "next lint && tsc"
}, },
"dependencies": { "dependencies": {
"next": "14.0.4", "next": "14.0.4",

View File

@@ -1,3 +1,3 @@
export type HeaderProps = { export type HeaderProps = {
pathname: string pathname: string;
} };

View File

@@ -8,7 +8,3 @@ export const langEnum = {
}; };
export type Lang = keyof typeof langEnum; export type Lang = keyof typeof langEnum;
export type LangProps<T = {}> = T & {
lang: Lang
}

View File

@@ -1,5 +1,22 @@
import { Lang } from "./lang"; import { Lang } from './lang';
export type Params<T = {}> = T & { params: { lang: Lang } }; export type SearchParams<S = {}> = {
searchParams: S & { [key: string]: string };
};
export type SearchParams<T = {}> = T & { searchParams: { [key: string]: string } }; export type Params<P = {}> = {
params: P;
};
export type LangParams = {
lang: Lang;
};
export type UriParams = {
uri?: string;
};
export type LayoutArgs<P = undefined> = P extends undefined ? {} : Params<P>;
export type PageArgs<P = undefined, S = undefined> = LayoutArgs<P> &
(S extends undefined ? {} : SearchParams<S>);