Skip to content

Commit 6c3d060

Browse files
committed
add type fixes
1 parent ec3521e commit 6c3d060

File tree

8 files changed

+41
-12
lines changed

8 files changed

+41
-12
lines changed

components/postList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Link from "next/link";
22
import Date_ from "./date";
33
import { postStars } from '../data/posts'
44
import siteConfig from '../siteConfig.json'
5+
import { ReactElement } from "react";
56

67
const PostStar = <>
78
<span className="star-container" title="star">*</span>
@@ -24,7 +25,7 @@ const PostStar = <>
2425
`}</style>
2526
</>
2627

27-
export default function PostList({ posts, showYears=false }) {
28+
export default function PostList({ posts, showYears = false }) {
2829
const years: Record<number, any> = {};
2930
posts.forEach(post => {
3031
const postDate = new Date(post.date);
@@ -36,7 +37,7 @@ export default function PostList({ posts, showYears=false }) {
3637
});
3738

3839
if (showYears) {
39-
const ret = [];
40+
const ret: ReactElement[] = []
4041
Object.keys(years)
4142
.sort((a, z) => parseInt(z) - parseInt(a))
4243
.forEach((year, i) => {

components/visuals/mazes/components.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function wilsonsAlgorithm(maze: Maze, ctx: CanvasRenderingContext2D, cance
7272

7373
// Continue until all cells have been visited
7474
while (unvisited.size > 0) {
75-
let path = [];
75+
let path: Cell[] = [];
7676
let current = randomMember(unvisited);
7777

7878
// Perform a random walk until reaching a cell already in the maze
@@ -238,15 +238,15 @@ export const IntroMaze = () => {
238238
renderMaze(maze, null, [], mazeCtx)
239239
renderDebug(maze, null, [], debugCtx)
240240
await sleep(1000);
241-
a.carveEdge(b)
241+
if (a && b) a.carveEdge(b)
242242
renderMaze(maze, b, [], mazeCtx)
243243
renderDebug(maze, null, [], debugCtx)
244244
await sleep(1000);
245-
b.carveEdge(c)
245+
if (b && c) b.carveEdge(c)
246246
renderMaze(maze, c, [], mazeCtx)
247247
renderDebug(maze, null, [], debugCtx)
248248
await sleep(1000);
249-
c.carveEdge(d)
249+
if (c && d) c.carveEdge(d)
250250
renderMaze(maze, d, [], mazeCtx)
251251
renderDebug(maze, null, [], debugCtx)
252252
await sleep(1000);

components/visuals/mazes/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ async function bfsFurthestCell(
6262
await new Promise((r) => setTimeout(r, stepTime));
6363
}
6464

65-
const { cell, dist } = queue.shift();
65+
const item = queue.shift();
66+
let cell;
67+
let dist;
68+
if (item) {
69+
cell = item.cell
70+
dist = item.dist
71+
}
72+
6673
if (dist > maxDist) {
6774
maxDist = dist;
6875
furthestCell = cell;

components/visuals/mazes/maze.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export function solveMazeWithRandomDPS(maze: Maze) {
8080
visited.add(`${x},${y}`);
8181

8282
const current = maze.getCell(x, y);
83+
if (!current) {
84+
return
85+
}
86+
8387
current.carveEdge(last);
8488

8589
const neighbors: Cell[] = shuffle(current.uncarvedEdges());

components/visuals/mazes/render.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function renderMaze(
178178

179179
export function renderBFSOverlay(
180180
maze: Maze,
181-
visited: Set<Cell>,
181+
visited: Set<Cell | null>,
182182
ctx: CanvasRenderingContext2D,
183183
) {
184184
const canvas = ctx.canvas;
@@ -196,7 +196,7 @@ export function renderBFSOverlay(
196196
for (let x = 0; x < width; x++) {
197197
const cell = maze.getCell(x, y);
198198

199-
if (visited.has(cell)) {
199+
if (visited.has(cell) && cell) {
200200
const centerX = x * cellSize + cellSize / 2;
201201
const centerY = y * cellSize + cellSize / 2;
202202

@@ -226,7 +226,7 @@ export function renderBFSOverlay(
226226

227227
export async function renderDebug(
228228
maze: Maze,
229-
currentCell: Cell,
229+
currentCell: Cell | null,
230230
currentPath: Cell[],
231231
ctx: CanvasRenderingContext2D,
232232
) {

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/basic-features/typescript for more information.

pages/[id].tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,30 @@ export async function getStaticProps({ params }) {
6969
let prevPost = null;
7070
let nextPost = null;
7171
const nextAndPrevPosts = getNextAndPrevPosts(params.id);
72+
// @ts-ignore
7273
if (nextAndPrevPosts.previous !== null) {
74+
// @ts-ignore
7375
prevPost = {
76+
// @ts-ignore
7477
id: nextAndPrevPosts.previous,
78+
// @ts-ignore
7579
...getPostData(nextAndPrevPosts.previous),
7680
};
7781
}
82+
// @ts-ignore
7883
if (nextAndPrevPosts.next !== null) {
84+
// @ts-ignore
7985
nextPost = {
86+
// @ts-ignore
8087
id: nextAndPrevPosts.next,
88+
// @ts-ignore
8189
...getPostData(nextAndPrevPosts.next),
8290
};
8391
}
8492

8593
return {
8694
props: {
95+
// @ts-ignore
8796
id: params.id,
8897
source: postData.content,
8998
imageMetadata,

tsconfig.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717
"resolveJsonModule": true,
1818
"isolatedModules": true,
1919
"jsx": "preserve",
20-
"incremental": true
20+
"incremental": true,
21+
"plugins": [
22+
{
23+
"name": "next"
24+
}
25+
],
26+
"strictNullChecks": true
2127
},
2228
"include": [
2329
"next-env.d.ts",
2430
"**/*.ts",
25-
"**/*.tsx"
31+
"**/*.tsx",
32+
".next/types/**/*.ts"
2633
],
2734
"exclude": [
2835
"node_modules"

0 commit comments

Comments
 (0)