Skip to content

Commit 25ad388

Browse files
authored
Merge pull request #29 from maxpetretta/dev
Enabled strict mode for typescript
2 parents 2c72668 + 7c2bf61 commit 25ad388

18 files changed

+125
-36
lines changed

components/Accordion.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Image from "next/image"
2+
import { Job } from "../lib/types"
23
import Badge from "./Badge"
34

4-
export default function Accordion({ job }) {
5+
export default function Accordion({ job }: { job: Job }) {
56
return (
67
<li className="link m-0 list-none rounded-none p-0" key={job.id}>
78
<label className="flex flex-wrap items-center">

components/Badge.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Image from "next/image"
22

3-
export default function Badge({ logo }) {
3+
export default function Badge({ logo }: { logo: string }) {
44
return (
55
<div className="m-1 flex max-w-xs transform items-center rounded-lg bg-gray-300 shadow-md transition-transform duration-300 hover:-translate-y-2 dark:bg-gray-700">
66
<div className="m-1 flex h-6 w-6 items-center justify-center rounded bg-white p-0.5 dark:bg-gray-300 md:m-2 md:h-14 md:w-14 md:rounded-lg md:p-2">

components/Entry.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Link from "next/link"
2+
import { PostMeta } from "../lib/types"
23

3-
export default function Entry({ post }) {
4+
export default function Entry({ post }: { post: PostMeta }) {
45
return (
56
<li className="list-none" key={post.slug}>
67
<Link href={"/blog/" + post.slug}>

components/Header.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default function Header() {
3434
className="no-link hidden xs:inline"
3535
aria-label="A link to the homepage"
3636
>
37+
{
38+
// eslint-disable-next-line
39+
}
3740
<img
3841
width={48}
3942
height={48}

components/Heading.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
export default function Heading({ tag, children }) {
1+
import { ReactNode } from "react"
2+
3+
export default function Heading({
4+
tag,
5+
children,
6+
}: {
7+
tag: string
8+
children: ReactNode
9+
}) {
210
const HTag = `${tag}` as keyof JSX.IntrinsicElements
3-
const anchor = getAnchor(children)
11+
const anchor = getAnchor(children as string)
412
const link = `#${anchor}`
513
return (
614
<HTag className="group flex items-center" id={anchor}>

components/Layout.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ import { MDXProvider } from "@mdx-js/react"
22
import { Tweet } from "mdx-embed"
33
import Head from "next/head"
44
import { useRouter } from "next/router"
5+
import { ReactNode } from "react"
6+
import { HeadingProps, LayoutProps } from "../lib/types"
57
import Footer from "./Footer"
68
import Header from "./Header"
79
import Heading from "./Heading"
810

9-
const H2 = (props) => <Heading tag="h2" {...props} />
10-
const H3 = (props) => <Heading tag="h3" {...props} />
11-
const H4 = (props) => <Heading tag="h4" {...props} />
12-
const H5 = (props) => <Heading tag="h5" {...props} />
11+
const H2 = (props: HeadingProps) => <Heading tag="h2" {...props} />
12+
const H3 = (props: HeadingProps) => <Heading tag="h3" {...props} />
13+
const H4 = (props: HeadingProps) => <Heading tag="h4" {...props} />
14+
const H5 = (props: HeadingProps) => <Heading tag="h5" {...props} />
1315

1416
const components = {
1517
h2: H2,
1618
h3: H3,
1719
h4: H4,
1820
h5: H5,
1921
Tweet,
20-
pre: (props) => <pre style={{ background: "#2d2a2e" }}>{props.children}</pre>,
22+
pre: (props: { children: ReactNode }) => (
23+
<pre style={{ background: "#2d2a2e" }}>{props.children}</pre>
24+
),
2125
}
2226

23-
export default function Layout(props) {
27+
export default function Layout(props: LayoutProps) {
2428
const { children, ...pageMeta } = props
2529
const router = useRouter()
2630
const meta = {

components/Post.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { Post as PostType } from "../lib/types"
1+
import { ReactNode } from "react"
2+
import { PostMeta } from "../lib/types"
23
import Layout from "./Layout"
34
import PostCard from "./PostCard"
45
import Title from "./Title"
56

6-
export default function Post({ meta, children }) {
7+
export default function Post({
8+
meta,
9+
children,
10+
}: {
11+
meta: PostMeta
12+
children: ReactNode
13+
}) {
714
return (
815
<>
916
<Layout
@@ -33,7 +40,7 @@ export default function Post({ meta, children }) {
3340
)
3441
}
3542

36-
export function getPostBySlug(slug: string): PostType {
43+
export function getPostBySlug(slug: string): PostMeta {
3744
const post = require(`../pages/blog/${slug}.mdx`)
3845

3946
return {

components/PostCard.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Image from "next/image"
22
import Link from "next/link"
3+
import { PostMeta } from "../lib/types"
34

4-
export default function PostCard({ post }) {
5+
export default function PostCard({ post }: { post: PostMeta }) {
56
return (
67
<Link href={"/blog/" + post.slug}>
78
<a className="no-link card max-w-md transform flex-col transition duration-300 hover:scale-105 hover:shadow-xl md:w-5/12">

components/TabBar.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export default function TabBar({ sections }) {
2-
var tabs = []
1+
import { Tabs } from "../lib/types"
2+
3+
export default function TabBar({ sections }: { sections: string[] }) {
4+
var tabs: Tabs[] = []
35
const widths = ["w-full", "w-1/2", "w-1/3", "w-1/4", "w-1/5", "w-1/6"]
46
const classes = [
57
"translate-x-0",
@@ -24,12 +26,14 @@ export default function TabBar({ sections }) {
2426
<div
2527
className="relative ml-0 flex h-8 flex-1 rounded-lg border-3 border-gray-400 bg-gray-400 text-sm dark:border-gray-700 dark:bg-gray-700 xs:ml-2 md:w-96 md:text-lg"
2628
onClick={() => {
27-
var selector = document.getElementById("selector")
28-
selector.classList.remove(...classes)
29-
selector.classList.add(current.class, "clicked")
30-
setTimeout(() => {
31-
selector.classList.remove("clicked")
32-
}, 1000)
29+
if (document.getElementById("selector")) {
30+
var selector = document.getElementById("selector")!
31+
selector.classList.remove(...classes)
32+
selector.classList.add(current.class, "clicked")
33+
setTimeout(() => {
34+
selector.classList.remove("clicked")
35+
}, 1000)
36+
}
3337
}}
3438
>
3539
<div

components/Title.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default function Title({ meta }) {
1+
import { PostMeta } from "../lib/types"
2+
3+
export default function Title({ meta }: { meta: PostMeta }) {
24
return (
35
<>
46
<h1 className="mb-3 md:mb-4">{meta.title}</h1>

components/Toggle.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export default function Toggle({ id, alt, onClick }) {
1+
export default function Toggle({
2+
id,
3+
alt,
4+
onClick,
5+
}: {
6+
id: string
7+
alt: string
8+
onClick: React.MouseEventHandler
9+
}) {
210
return (
311
<label
412
className="ml-2 inline-flex h-6 w-10 flex-shrink-0 cursor-pointer rounded-full bg-gray-400 align-middle shadow-inner dark:bg-gray-500 xs:h-7 xs:w-12 md:ml-5"

lib/posts.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from "fs"
22
import path from "path"
3-
import { Post } from "./types"
3+
import { PostMeta } from "../lib/types"
44

55
const postDirectory = path.join(process.cwd(), "/pages/blog")
66

7-
export function getAllPosts(): Post[] {
7+
export function getAllPosts(): PostMeta[] {
88
const files = fs.readdirSync(postDirectory)
99
const posts = files.map((file) => {
1010
const post = require(`../pages/blog/${file}`)
@@ -14,6 +14,5 @@ export function getAllPosts(): Post[] {
1414
...post.meta,
1515
}
1616
})
17-
console.log(posts)
1817
return posts
1918
}

lib/types.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ReactNode } from "react"
2+
13
export type Job = {
24
id: number
35
company: string
@@ -10,7 +12,7 @@ export type Job = {
1012
description: string
1113
}
1214

13-
export type Post = {
15+
export type PostMeta = {
1416
slug: string
1517
title: string
1618
description: string
@@ -21,3 +23,22 @@ export type Post = {
2123
icon: string
2224
related: string
2325
}
26+
27+
export type LayoutProps = {
28+
title?: string
29+
description?: string
30+
image?: string
31+
date?: string
32+
type?: string
33+
children?: React.ReactNode
34+
}
35+
36+
export type HeadingProps = {
37+
tag?: string
38+
children: ReactNode
39+
}
40+
41+
export type Tabs = {
42+
section: string
43+
class: string
44+
}

package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"shiki": "^0.10.1"
2626
},
2727
"devDependencies": {
28+
"@types/mdx-js__react": "^1.5.5",
2829
"@types/node": "^18.7.16",
2930
"@types/react": "^18.0.19",
3031
"autoprefixer": "^10.4.2",

pages/blog.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import Entry from "../components/Entry"
33
import Layout from "../components/Layout"
44
import PostCard from "../components/PostCard"
55
import { getAllPosts } from "../lib/posts"
6-
import { Post } from "../lib/types"
6+
import { PostMeta } from "../lib/types"
77

8-
export default function Blog({ posts, postCount, postsByYear, years }) {
8+
export default function Blog({
9+
posts,
10+
postCount,
11+
postsByYear,
12+
years,
13+
}: {
14+
posts: PostMeta[]
15+
postCount: number
16+
postsByYear: any
17+
years: string[]
18+
}) {
919
return (
1020
<>
1121
<Layout title="Blog | Max Petretta">
@@ -31,7 +41,7 @@ export default function Blog({ posts, postCount, postsByYear, years }) {
3141
<h2 className="mb-0">{year}</h2>
3242
<hr className="mt-2 mb-8 md:mt-3 md:mb-10" />
3343
<ul className="list">
34-
{postsByYear[year].map((post: Post) => {
44+
{postsByYear[year].map((post: PostMeta) => {
3545
return <Entry key={post.slug} post={post} />
3646
})}
3747
</ul>
@@ -47,7 +57,7 @@ export default function Blog({ posts, postCount, postsByYear, years }) {
4757
export const getStaticProps: GetStaticProps = async () => {
4858
const posts = getAllPosts().reverse()
4959
const postCount = posts.length
50-
let postsByYear = {}
60+
let postsByYear: any = {}
5161

5262
posts.map((post) => {
5363
const year = post.date.split("-")[0]
@@ -61,7 +71,7 @@ export const getStaticProps: GetStaticProps = async () => {
6171
}
6272
}
6373

64-
export function getFeaturedPosts(posts: Post[]): Post[] {
74+
export function getFeaturedPosts(posts: PostMeta[]): PostMeta[] {
6575
const featured = ["twitt3r", "tech-stack"]
6676

6777
const sorted = posts

pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import SkillCard from "../components/SkillCard"
77
import { getJobs } from "../lib/jobs"
88
import { Job } from "../lib/types"
99

10-
export default function Home({ jobs }) {
10+
export default function Home({ jobs }: { jobs: Job[] }) {
1111
return (
1212
<>
1313
<Layout>

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,
7-
"strict": false,
7+
"strict": true,
88
"forceConsistentCasingInFileNames": true,
99
"noEmit": true,
1010
"incremental": true,

0 commit comments

Comments
 (0)