From 7c2bf618db020aed2df8c1dd8e09b9f5b55cd49b Mon Sep 17 00:00:00 2001 From: Max Petretta Date: Sun, 18 Sep 2022 22:35:25 -0400 Subject: [PATCH] Enabled strict mode for typescript --- components/Accordion.tsx | 3 ++- components/Badge.tsx | 2 +- components/Entry.tsx | 3 ++- components/Header.tsx | 3 +++ components/Heading.tsx | 12 ++++++++++-- components/Layout.tsx | 16 ++++++++++------ components/Post.tsx | 13 ++++++++++--- components/PostCard.tsx | 3 ++- components/TabBar.tsx | 20 ++++++++++++-------- components/Title.tsx | 4 +++- components/Toggle.tsx | 10 +++++++++- lib/posts.ts | 5 ++--- lib/types.ts | 23 ++++++++++++++++++++++- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + pages/blog.tsx | 20 +++++++++++++++----- pages/index.tsx | 2 +- tsconfig.json | 2 +- 18 files changed, 125 insertions(+), 36 deletions(-) diff --git a/components/Accordion.tsx b/components/Accordion.tsx index 9ff6db5..1c40f08 100644 --- a/components/Accordion.tsx +++ b/components/Accordion.tsx @@ -1,7 +1,8 @@ import Image from "next/image" +import { Job } from "../lib/types" import Badge from "./Badge" -export default function Accordion({ job }) { +export default function Accordion({ job }: { job: Job }) { return (
  • diff --git a/components/Header.tsx b/components/Header.tsx index bd1c5aa..c37dfa8 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -34,6 +34,9 @@ export default function Header() { className="no-link hidden xs:inline" aria-label="A link to the homepage" > + { + // eslint-disable-next-line + } diff --git a/components/Layout.tsx b/components/Layout.tsx index a8cc65e..ac61fc5 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -2,14 +2,16 @@ import { MDXProvider } from "@mdx-js/react" import { Tweet } from "mdx-embed" import Head from "next/head" import { useRouter } from "next/router" +import { ReactNode } from "react" +import { HeadingProps, LayoutProps } from "../lib/types" import Footer from "./Footer" import Header from "./Header" import Heading from "./Heading" -const H2 = (props) => -const H3 = (props) => -const H4 = (props) => -const H5 = (props) => +const H2 = (props: HeadingProps) => +const H3 = (props: HeadingProps) => +const H4 = (props: HeadingProps) => +const H5 = (props: HeadingProps) => const components = { h2: H2, @@ -17,10 +19,12 @@ const components = { h4: H4, h5: H5, Tweet, - pre: (props) =>
    {props.children}
    , + pre: (props: { children: ReactNode }) => ( +
    {props.children}
    + ), } -export default function Layout(props) { +export default function Layout(props: LayoutProps) { const { children, ...pageMeta } = props const router = useRouter() const meta = { diff --git a/components/Post.tsx b/components/Post.tsx index 37deb84..814c892 100644 --- a/components/Post.tsx +++ b/components/Post.tsx @@ -1,9 +1,16 @@ -import { Post as PostType } from "../lib/types" +import { ReactNode } from "react" +import { PostMeta } from "../lib/types" import Layout from "./Layout" import PostCard from "./PostCard" import Title from "./Title" -export default function Post({ meta, children }) { +export default function Post({ + meta, + children, +}: { + meta: PostMeta + children: ReactNode +}) { return ( <> diff --git a/components/TabBar.tsx b/components/TabBar.tsx index 846271c..4b74aa6 100644 --- a/components/TabBar.tsx +++ b/components/TabBar.tsx @@ -1,5 +1,7 @@ -export default function TabBar({ sections }) { - var tabs = [] +import { Tabs } from "../lib/types" + +export default function TabBar({ sections }: { sections: string[] }) { + var tabs: Tabs[] = [] const widths = ["w-full", "w-1/2", "w-1/3", "w-1/4", "w-1/5", "w-1/6"] const classes = [ "translate-x-0", @@ -24,12 +26,14 @@ export default function TabBar({ sections }) {
    { - var selector = document.getElementById("selector") - selector.classList.remove(...classes) - selector.classList.add(current.class, "clicked") - setTimeout(() => { - selector.classList.remove("clicked") - }, 1000) + if (document.getElementById("selector")) { + var selector = document.getElementById("selector")! + selector.classList.remove(...classes) + selector.classList.add(current.class, "clicked") + setTimeout(() => { + selector.classList.remove("clicked") + }, 1000) + } }} >

    {meta.title}

    diff --git a/components/Toggle.tsx b/components/Toggle.tsx index 4f1c324..08df7f4 100644 --- a/components/Toggle.tsx +++ b/components/Toggle.tsx @@ -1,4 +1,12 @@ -export default function Toggle({ id, alt, onClick }) { +export default function Toggle({ + id, + alt, + onClick, +}: { + id: string + alt: string + onClick: React.MouseEventHandler +}) { return (