Skip to content

Commit fb5ba99

Browse files
Update to TypeScript 6.0 (#596)
1 parent e665e8e commit fb5ba99

File tree

18 files changed

+229
-255
lines changed

18 files changed

+229
-255
lines changed

package-lock.json

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

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@
4646
"@docusaurus/tsconfig": "^3.10.0",
4747
"@docusaurus/types": "^3.10.0",
4848
"@eslint/js": "~9.39.4",
49-
"dotenv": "^17.3.1",
49+
"@types/lodash": "^4.17.24",
50+
"dotenv": "^17.4.1",
5051
"eslint": "~9.39.4",
5152
"eslint-plugin-react": "^7.37.5",
5253
"eslint-plugin-react-hooks": "^7.0.1",
5354
"globals": "^17.4.0",
54-
"lodash": "^4.17.23",
55+
"lodash": "^4.18.1",
5556
"prettier": "^3.8.1",
5657
"raw-loader": "^4.0.2",
5758
"remark": "^15.0.1",
5859
"serve-handler": "^6.1.7",
59-
"typescript": "^5.9.3",
60-
"typescript-eslint": "^8.57.1",
60+
"typescript": "^6.0.2",
61+
"typescript-eslint": "^8.58.0",
6162
"unist-util-visit": "^5.1.0"
6263
},
6364
"overrides": {

sidebarsAdEngine.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
2-
import type { SidebarItem, SidebarItemCategory, SidebarItemConfig, SidebarItemDoc } from '@docusaurus/plugin-content-docs/lib/sidebars/types.d.ts';
2+
import type {
3+
SidebarItem,
4+
SidebarItemCategoryConfig,
5+
SidebarItemConfig,
6+
SidebarItemDoc,
7+
} from '@docusaurus/plugin-content-docs/lib/sidebars/types.d.ts';
38
import apiSidebar from './adengine/reference/sidebar';
49

5-
function isCategory(item: SidebarItemConfig): item is SidebarItemCategory {
10+
function isCategory(item: SidebarItemConfig): item is SidebarItemCategoryConfig {
611
return (item as SidebarItem).type === 'category';
712
}
813

sidebarsMillicast.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
2-
import type { SidebarItem, SidebarItemCategory, SidebarItemConfig, SidebarItemDoc } from '@docusaurus/plugin-content-docs/lib/sidebars/types.d.ts';
2+
import type {
3+
SidebarItem,
4+
SidebarItemCategoryConfig,
5+
SidebarItemConfig,
6+
SidebarItemDoc,
7+
} from '@docusaurus/plugin-content-docs/lib/sidebars/types.d.ts';
38
import rawMillicastApiSidebar from './millicast/api/sidebar';
49
import rawMillicastAdvancedReportingApiSidebar from './millicast/api/reporting/sidebar';
510
import rawMillicastDirectorApiSidebar from './millicast/api/director/sidebar';
611

7-
function isCategory(item: SidebarItemConfig): item is SidebarItemCategory {
12+
function isCategory(item: SidebarItemConfig): item is SidebarItemCategoryConfig {
813
return (item as SidebarItem).type === 'category';
914
}
1015

@@ -17,7 +22,7 @@ function removeHiddenItems(data: SidebarItemConfig[], hiddenIds: string[]): Side
1722
return data
1823
.map((category) => {
1924
// filter out items from other categories that match the hidden IDs
20-
if (isCategory(category)) {
25+
if (isCategory(category) && Array.isArray(category.items)) {
2126
// filter out the items that match any of the hidden IDs
2227
const filteredItems = category.items.filter((item) => !(isDoc(item) && hiddenIdsSet.has(item.id)));
2328

@@ -40,55 +45,59 @@ function removeHiddenItems(data: SidebarItemConfig[], hiddenIds: string[]): Side
4045

4146
function fixLabels(items: SidebarItemConfig[], replacements: Record<string, string> = {}): SidebarItemConfig[] {
4247
return items.map((item) => {
43-
if (!(isCategory(item) || isDoc(item))) {
44-
return item;
45-
}
46-
let label = item.label;
47-
if (label) {
48+
if ((isCategory(item) || isDoc(item)) && item.label) {
49+
let label = item.label;
4850
if (replacements[label]) {
4951
// Replace label
5052
label = replacements[label];
53+
item = { ...item, label };
5154
} else if (isCategory(item)) {
5255
// Add spaces between capitalized words
5356
label = item.label.replace(/([a-z])([A-Z])/g, '$1 $2');
57+
item = { ...item, label };
5458
}
5559
}
56-
if (isCategory(item)) {
57-
return { ...item, label, items: fixLabels(item.items, replacements) };
58-
} else {
59-
return { ...item, label };
60+
if (isCategory(item) && Array.isArray(item.items)) {
61+
const items = fixLabels(item.items, replacements);
62+
item = { ...item, items };
6063
}
64+
return item;
6165
});
6266
}
6367

6468
function mergeCategories(items: SidebarItemConfig[]): SidebarItemConfig[] {
6569
for (let index = 0; index < items.length; index++) {
6670
const item = items[index];
67-
if (isCategory(item)) {
68-
// Merge categories with same label
69-
const otherIndex = items.findIndex((other, otherIndex) => {
70-
return otherIndex > index && isCategory(other) && other.label === item.label;
71+
if (!isCategory(item) || !Array.isArray(item.items)) {
72+
continue;
73+
}
74+
// Merge categories with same label
75+
const otherIndex = items.findIndex((other, otherIndex) => {
76+
return otherIndex > index && isCategory(other) && other.label === item.label;
77+
});
78+
if (otherIndex < 0) {
79+
continue;
80+
}
81+
const otherItem = items[otherIndex] as SidebarItemCategoryConfig;
82+
if (!Array.isArray(otherItem.items)) {
83+
continue;
84+
}
85+
const mergedItems = [...otherItem.items];
86+
for (const otherChild of item.items) {
87+
// Insert before existing child with same label (if any).
88+
// Otherwise, insert at the end.
89+
const existingChildIndex = mergedItems.findIndex((existingChild) => {
90+
return isDoc(otherChild) && isDoc(existingChild) && existingChild.label === otherChild.label;
7191
});
72-
if (otherIndex > 0) {
73-
const otherItem = items[otherIndex] as SidebarItemCategory;
74-
const mergedItems = [...otherItem.items];
75-
for (const otherChild of item.items) {
76-
// Insert before existing child with same label (if any).
77-
// Otherwise, insert at the end.
78-
const existingChildIndex = mergedItems.findIndex((existingChild) => {
79-
return isDoc(otherChild) && isDoc(existingChild) && existingChild.label === otherChild.label;
80-
});
81-
if (existingChildIndex >= 0) {
82-
mergedItems.splice(existingChildIndex, 0, otherChild);
83-
} else {
84-
mergedItems.push(otherChild);
85-
}
86-
}
87-
items[index] = { ...item, items: mergedItems };
88-
items.splice(otherIndex, 1);
89-
index--;
92+
if (existingChildIndex >= 0) {
93+
mergedItems.splice(existingChildIndex, 0, otherChild);
94+
} else {
95+
mergedItems.push(otherChild);
9096
}
9197
}
98+
items[index] = { ...item, items: mergedItems };
99+
items.splice(otherIndex, 1);
100+
index--;
92101
}
93102
return items;
94103
}

src/components/PlatformSelect/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function PlatformSelect({ docsPluginId, version, className, ...pr
3535
// selectedItem is always null during SSR, so look up the initial platform manually
3636
platforms.find((desc) => desc.platform === lastPlatformName) ??
3737
// last platform does not exist in the active doc version, fall back to default platform
38-
platforms.find((desc) => desc.platform === defaultPlatformName);
38+
platforms.find((desc) => desc.platform === defaultPlatformName)!;
3939
return (
4040
<span className={clsx(styles.platformValue)}>
4141
<Icon className={styles.platformIcon} icon={icon} defaultIcon="" />
@@ -48,8 +48,8 @@ export default function PlatformSelect({ docsPluginId, version, className, ...pr
4848
>
4949
{(desc) => {
5050
const { platform, label, description, icon } = desc;
51-
const sidebar = findSidebarInVersions(platform, versionCandidates);
52-
const sidebarLink = (activeDoc && getPlatformDoc(docsPluginId, activeVersion, activeDoc, platform)?.path) ?? sidebar.link.path;
51+
const sidebar = findSidebarInVersions(platform, versionCandidates)!;
52+
const sidebarLink = (activeDoc && getPlatformDoc(docsPluginId, activeVersion!, activeDoc, platform)?.path) ?? sidebar.link!.path;
5353
return (
5454
<Item
5555
id={platform}

src/components/SidebarCategoryDocCardList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function isCategory(item: PropSidebarItem): item is PropSidebarItemCategory {
1414

1515
export default function SidebarCategoryDocCardList({ headingLevel, ...props }: Props) {
1616
const sidebar = useDocsSidebar();
17-
const categories = sidebar.items.filter(isCategory);
17+
const categories = sidebar?.items.filter(isCategory) ?? [];
1818
return categories.map((category) => (
1919
<Fragment key={category.label}>
2020
<Heading as={headingLevel ?? 'h2'}>{category.label}</Heading>

src/components/SidebarDocCardList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function isCategory(item: PropSidebarItem): item is PropSidebarItemCategory {
1515
export default function SidebarDocCardList({ headingLevel, ...props }: Props) {
1616
const doc = useDoc();
1717
const sidebar = useDocsSidebar();
18-
const items = sidebar.items
18+
const items = (sidebar?.items ?? [])
1919
// Hide the current doc page from list
2020
.filter((item) => !(item.type === 'link' && item.docId === doc.metadata.id));
2121
if (headingLevel) {

src/components/ThreeCardList/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React from 'react';
22
import clsx from 'clsx';
3-
import type { Props } from '@theme/DocCardList';
3+
import type { Props as DocCardProps } from '@theme/DocCardList';
4+
import type { PropSidebarItem } from '@docusaurus/plugin-content-docs';
45
import DocCard from '@theme/DocCard';
56

7+
export interface Props extends DocCardProps {
8+
readonly items: PropSidebarItem[];
9+
}
10+
611
export default function ThreeCardList(props: Props) {
712
const { items, className } = props;
813
return (

src/contexts/lastPlatform.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { defaultPlatformName } from '@site/src/util/platform';
99

1010
const isDocsPluginEnabled: boolean = !!useAllDocsData;
1111

12-
type LastPlatformName = PlatformName | null;
12+
type LastPlatformName = PlatformName;
1313

1414
/** State for a single docs plugin instance */
1515
type DocsLastPlatformPluginState = {
16-
lastPlatformName: LastPlatformName;
16+
lastPlatformName: LastPlatformName | null;
1717
};
1818

1919
/**
@@ -75,7 +75,7 @@ function LastPlatformContextProviderUnsafe({ children }: { children: ReactNode }
7575
const lastPlatformName = state[pluginId].lastPlatformName;
7676
if (activeDoc && (!lastPlatformName || lastPlatformName !== docSidebarName)) {
7777
if (isDocSharedWithPlatform(pluginId, activeDoc, lastPlatformName || defaultPlatformName)) {
78-
if (lastPlatformName && activeVersion.sidebars[lastPlatformName]) {
78+
if (lastPlatformName && activeVersion?.sidebars?.[lastPlatformName]) {
7979
// Prefer last platform for cross-platform docs
8080
} else {
8181
// No last platform yet or platform not in this version, so update to default platform
@@ -113,7 +113,7 @@ export function useLastPlatform(): {
113113
lastPlatformName: LastPlatformName;
114114
saveLastPlatform: (lastPlatform: LastPlatformName) => void;
115115
} {
116-
const { pluginId } = useActivePlugin({ failfast: true });
116+
const { pluginId } = useActivePlugin({ failfast: true })!;
117117
return useLastPlatformByPluginId(pluginId);
118118
}
119119

@@ -154,5 +154,5 @@ export function useLastPlatformMainLink(pluginId: string): string | null {
154154
}
155155

156156
const sidebar = findSidebarInVersions(platformName, versionCandidates);
157-
return sidebar.link.path;
157+
return sidebar?.link?.path ?? null;
158158
}

src/theme/DocBreadcrumbs/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,24 @@ function getMainDocTitle(docPluginId: string): string | null {
5454
return 'Live Streaming';
5555
case 'millicast':
5656
return 'Real-time Streaming';
57+
default:
58+
return null;
5759
}
5860
}
5961

6062
function useSidebarBreadcrumbsWithMainDoc(): PropSidebarBreadcrumbsItem[] | null {
6163
const breadcrumbs = useSidebarBreadcrumbs();
6264
const { pluginId } = useActivePlugin({ failfast: true })!;
6365
const { activeVersion, activeDoc } = useActiveDocContext(pluginId);
64-
const versionMainDoc = activeVersion.docs.find((doc) => doc.id === activeVersion.mainDocId)!;
65-
const mainDocUrl = useBaseUrl(versionMainDoc.path);
66+
const versionMainDoc = activeVersion?.docs.find((doc) => doc.id === activeVersion.mainDocId);
67+
const mainDocUrl = useBaseUrl(versionMainDoc?.path);
6668
const mainDocTitle = getMainDocTitle(pluginId);
67-
if (!breadcrumbs || !mainDocTitle) {
69+
if (!breadcrumbs || !versionMainDoc || !mainDocTitle) {
6870
return breadcrumbs;
6971
}
7072
const mainDocItem: PropSidebarItemLink = {
7173
type: 'link',
72-
href: activeDoc.id === activeVersion.mainDocId ? undefined : mainDocUrl,
74+
href: activeDoc?.id === activeVersion?.mainDocId ? '' : mainDocUrl,
7375
label: mainDocTitle,
7476
docId: versionMainDoc.id,
7577
};

0 commit comments

Comments
 (0)