Merged in feat/improve-typings (pull request #4)
feat(WEB-36): improve typings Approved-by: Christel Westerberg
This commit is contained in:
@@ -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<SearchParams>) {
|
||||
}: PageArgs<LangParams, UriParams>) {
|
||||
try {
|
||||
if (!searchParams.uri) {
|
||||
throw new Error("Bad URI");
|
||||
}
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mockCms",
|
||||
|
||||
@@ -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<Params>) {
|
||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||
return (
|
||||
<html lang={params.lang}>
|
||||
<head>
|
||||
|
||||
@@ -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 <Da />;
|
||||
|
||||
@@ -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<HeaderProps>) {
|
||||
export default function Header({ lang, pathname }: LangParams & HeaderProps) {
|
||||
switch (lang) {
|
||||
case langEnum.sv:
|
||||
return <Sv pathname={pathname} />;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export type HeaderProps = {
|
||||
pathname: string
|
||||
}
|
||||
pathname: string;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,3 @@ export const langEnum = {
|
||||
};
|
||||
|
||||
export type Lang = keyof typeof langEnum;
|
||||
|
||||
export type LangProps<T = {}> = T & {
|
||||
lang: Lang
|
||||
}
|
||||
@@ -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>);
|
||||
|
||||
Reference in New Issue
Block a user