Skip to content

Commit 11ecdc0

Browse files
[deps]: Update typescript to v6 (#795)
* [deps]: Update typescript to v6 * fix `JSX` import; disable remaining typechecks * add type definition to fix `remark-kroki` type lookup failure * fix typechecks * use enum-like pattern --------- Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
1 parent ea6963a commit 11ecdc0

10 files changed

Lines changed: 87 additions & 38 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"husky": "9.1.7",
5050
"lint-staged": "16.4.0",
5151
"prettier": "3.8.1",
52-
"typescript": "5.9.2"
52+
"typescript": "6.0.2"
5353
},
5454
"browserslist": {
5555
"production": [

src/components/AdrTable.tsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,61 @@
11
import React from "react";
22

3-
const formatDate = (date: Date) => {
3+
const formatDate = (date: Date): string | undefined => {
44
try {
55
return date.toISOString().split("T")[0];
6-
} catch {}
6+
} catch {
7+
return undefined;
8+
}
79
};
810

9-
const badgeColors = {
10-
Proposed: "primary",
11-
Accepted: "success",
12-
Rejected: "danger",
13-
Deprecated: "warning",
14-
Superseded: "warning",
11+
const AdrStatus = {
12+
Proposed: "Proposed",
13+
Accepted: "Accepted",
14+
Rejected: "Rejected",
15+
Deprecated: "Deprecated",
16+
Superseded: "Superseded",
17+
} as const;
18+
19+
type AdrStatus = (typeof AdrStatus)[keyof typeof AdrStatus];
20+
21+
const badgeColors: Record<AdrStatus, string> = {
22+
[AdrStatus.Proposed]: "primary",
23+
[AdrStatus.Accepted]: "success",
24+
[AdrStatus.Rejected]: "danger",
25+
[AdrStatus.Deprecated]: "warning",
26+
[AdrStatus.Superseded]: "warning",
1527
};
1628

17-
export default function AdrTable({ frontMatter }): JSX.Element {
29+
function isAdrStatus(value: unknown): value is AdrStatus {
30+
return typeof value === "string" && value in AdrStatus;
31+
}
32+
33+
interface AdrFrontMatter {
34+
adr: string;
35+
status?: string;
36+
date: Date;
37+
}
38+
39+
export default function AdrTable({
40+
frontMatter,
41+
}: {
42+
frontMatter: AdrFrontMatter;
43+
}): React.JSX.Element {
44+
const { status } = frontMatter;
45+
const badgeColor = isAdrStatus(status) ? badgeColors[status] : "secondary";
46+
1847
return (
1948
<table>
2049
<tbody>
2150
<tr>
2251
<th>ID:</th>
2352
<td>ADR-{frontMatter.adr}</td>
2453
</tr>
25-
{frontMatter.status && (
54+
{status && (
2655
<tr>
2756
<th>Status:</th>
2857
<td>
29-
<span className={`badge badge--${badgeColors[frontMatter.status] ?? "secondary"}`}>
30-
{frontMatter.status?.toUpperCase()}
31-
</span>
58+
<span className={`badge badge--${badgeColor}`}>{status.toUpperCase()}</span>
3259
</td>
3360
</tr>
3461
)}

src/components/Bitwarden.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from "react";
1+
import React, { type ReactNode } from "react";
22
import { useDevMode } from "../contexts/devMode";
33

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

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

src/components/Community.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from "react";
1+
import React, { type ReactNode } from "react";
22
import { useDevMode } from "../contexts/devMode";
33

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

77
if (devMode === "community") {
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from "react";
22
import DropdownNavbarItem from "@theme-original/NavbarItem/DropdownNavbarItem";
3+
import type { Props as DropdownNavbarItemProps } from "@theme/NavbarItem/DropdownNavbarItem";
4+
import type { LinkLikeNavbarItemProps } from "@theme/NavbarItem";
35
import { useDevMode, DevModes } from "@site/src/contexts/devMode";
46

57
const dropdownOptions = [
@@ -11,28 +13,31 @@ const dropdownOptions = [
1113
id: DevModes.bitwarden,
1214
label: "Bitwarden Developer",
1315
},
14-
];
16+
] as const;
17+
18+
interface Props extends Omit<DropdownNavbarItemProps, "items" | "label"> {
19+
readonly dropdownItemsBefore?: LinkLikeNavbarItemProps[];
20+
readonly dropdownItemsAfter?: LinkLikeNavbarItemProps[];
21+
}
1522

1623
export default function DevDropdown({
1724
mobile,
1825
dropdownItemsBefore,
1926
dropdownItemsAfter,
2027
...props
21-
}): JSX.Element {
28+
}: Props): React.JSX.Element {
2229
const { devMode, setDevMode } = useDevMode();
2330

24-
const items = dropdownOptions.map((item) => {
25-
return {
26-
label: item.label,
27-
to: "#",
28-
onClick: (e) => {
29-
setDevMode(item.id);
30-
e.preventDefault();
31-
},
32-
};
33-
});
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+
}));
3439

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

3742
return <DropdownNavbarItem {...props} mobile={mobile} label={dropdownLabel} items={items} />;
3843
}

src/contexts/devMode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function useContextValue(): ContextValue {
7474
);
7575
}
7676

77-
export function DevModeProvider({ children }: { children: ReactNode }): JSX.Element {
77+
export function DevModeProvider({ children }: { children: ReactNode }): React.JSX.Element {
7878
const value = useContextValue();
7979
return <Context.Provider value={value}>{children}</Context.Provider>;
8080
}

src/theme/Layout/Provider/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DevModeProvider } from "@site/src/contexts/devMode";
77

88
const Provider = composeProviders([DevModeProvider]);
99

10-
export default function LayoutProvider({ children }: Props): JSX.Element {
10+
export default function LayoutProvider({ children }: Props): React.JSX.Element {
1111
return (
1212
<ThemeLayoutProvider>
1313
<Provider>{children}</Provider>

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is not used in compilation. It is here just for a nice editor experience.
33
"extends": "@docusaurus/tsconfig",
44
"compilerOptions": {
5-
"baseUrl": "."
5+
"baseUrl": null,
6+
"paths": {
7+
"@site/*": ["./*"]
8+
}
69
}
710
}

types/remark-kroki.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// FIXME: delete this file once `remark-kroki` ships its own type definitions
2+
// (or once `@types/remark-kroki` is published on DefinitelyTyped). Track
3+
// upstream at https://github.com/show-docs/remark-kroki.
4+
declare module "remark-kroki" {
5+
export interface RemarkKrokiOptions {
6+
server?: string;
7+
headers?: Record<string, string>;
8+
alias?: string[];
9+
output?: string;
10+
target?: "html" | "mdx3";
11+
}
12+
13+
export function remarkKroki(options?: RemarkKrokiOptions): (tree: unknown) => Promise<void>;
14+
}

0 commit comments

Comments
 (0)