Skip to content

Commit 934545c

Browse files
committed
replace FIXMEs with typechecking fixes
1 parent 3f6b8f2 commit 934545c

4 files changed

Lines changed: 44 additions & 32 deletions

File tree

src/components/AdrTable.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// FIXME: remove @ts-nocheck and address type errors in this file
2-
// @ts-nocheck
31
import React from "react";
42

5-
const formatDate = (date: Date) => {
3+
const formatDate = (date: Date): string | undefined => {
64
try {
75
return date.toISOString().split("T")[0];
8-
} catch {}
6+
} catch {
7+
return undefined;
8+
}
99
};
1010

1111
const badgeColors = {
@@ -16,21 +16,34 @@ const badgeColors = {
1616
Superseded: "warning",
1717
};
1818

19-
export default function AdrTable({ frontMatter }): React.JSX.Element {
19+
const isBadgeColorKey = (key: string): key is keyof typeof badgeColors => key in badgeColors;
20+
21+
interface AdrFrontMatter {
22+
adr: string;
23+
status?: string;
24+
date: Date;
25+
}
26+
27+
export default function AdrTable({
28+
frontMatter,
29+
}: {
30+
frontMatter: AdrFrontMatter;
31+
}): React.JSX.Element {
32+
const { status } = frontMatter;
33+
const badgeColor = status && isBadgeColorKey(status) ? badgeColors[status] : "secondary";
34+
2035
return (
2136
<table>
2237
<tbody>
2338
<tr>
2439
<th>ID:</th>
2540
<td>ADR-{frontMatter.adr}</td>
2641
</tr>
27-
{frontMatter.status && (
42+
{status && (
2843
<tr>
2944
<th>Status:</th>
3045
<td>
31-
<span className={`badge badge--${badgeColors[frontMatter.status] ?? "secondary"}`}>
32-
{frontMatter.status?.toUpperCase()}
33-
</span>
46+
<span className={`badge badge--${badgeColor}`}>{status.toUpperCase()}</span>
3447
</td>
3548
</tr>
3649
)}

src/components/Bitwarden.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// FIXME: remove @ts-nocheck and address type errors in this file
2-
// @ts-nocheck
3-
import React from "react";
1+
import React, { type ReactNode } from "react";
42
import { useDevMode } from "../contexts/devMode";
53

6-
export default function Bitwarden({ children }): React.JSX.Element {
4+
export default function Bitwarden({ children }: { children: ReactNode }): React.JSX.Element {
75
const { devMode } = useDevMode();
86

97
if (devMode === "bitwarden") {

src/components/Community.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// FIXME: remove @ts-nocheck and address type errors in this file
2-
// @ts-nocheck
3-
import React from "react";
1+
import React, { type ReactNode } from "react";
42
import { useDevMode } from "../contexts/devMode";
53

6-
export default function Community({ children }): React.JSX.Element {
4+
export default function Community({ children }: { children: ReactNode }): React.JSX.Element {
75
const { devMode } = useDevMode();
86

97
if (devMode === "community") {
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// FIXME: remove @ts-nocheck and address type errors in this file
2-
// @ts-nocheck
31
import React from "react";
42
import DropdownNavbarItem from "@theme-original/NavbarItem/DropdownNavbarItem";
3+
import type { Props as DropdownNavbarItemProps } from "@theme/NavbarItem/DropdownNavbarItem";
4+
import type { LinkLikeNavbarItemProps } from "@theme/NavbarItem";
55
import { useDevMode, DevModes } from "@site/src/contexts/devMode";
66

77
const dropdownOptions = [
@@ -13,28 +13,31 @@ const dropdownOptions = [
1313
id: DevModes.bitwarden,
1414
label: "Bitwarden Developer",
1515
},
16-
];
16+
] as const;
17+
18+
interface Props extends Omit<DropdownNavbarItemProps, "items" | "label"> {
19+
readonly dropdownItemsBefore?: LinkLikeNavbarItemProps[];
20+
readonly dropdownItemsAfter?: LinkLikeNavbarItemProps[];
21+
}
1722

1823
export default function DevDropdown({
1924
mobile,
2025
dropdownItemsBefore,
2126
dropdownItemsAfter,
2227
...props
23-
}): React.JSX.Element {
28+
}: Props): React.JSX.Element {
2429
const { devMode, setDevMode } = useDevMode();
2530

26-
const items = dropdownOptions.map((item) => {
27-
return {
28-
label: item.label,
29-
to: "#",
30-
onClick: (e) => {
31-
setDevMode(item.id);
32-
e.preventDefault();
33-
},
34-
};
35-
});
31+
const items: DropdownNavbarItemProps["items"] = dropdownOptions.map((item) => ({
32+
label: item.label,
33+
to: "#",
34+
onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
35+
setDevMode(item.id);
36+
e.preventDefault();
37+
},
38+
}));
3639

37-
const dropdownLabel = dropdownOptions.find((i) => i.id == devMode).label;
40+
const dropdownLabel = dropdownOptions.find((i) => i.id === devMode)?.label;
3841

3942
return <DropdownNavbarItem {...props} mobile={mobile} label={dropdownLabel} items={items} />;
4043
}

0 commit comments

Comments
 (0)