) => {
e.preventDefault();
- const targetElement =
+ const targetElement: HTMLElement | null =
document.querySelector('main:first-of-type') ||
document.querySelector('.main-wrapper');
@@ -34,7 +34,7 @@ function SkipToContent(): JSX.Element {
useEffect(() => {
if (!location.hash) {
- programmaticFocus(containerRef.current);
+ programmaticFocus(containerRef.current!);
}
}, [location.pathname]);
diff --git a/packages/docusaurus-theme-classic/src/theme/TOCInline/index.tsx b/packages/docusaurus-theme-classic/src/theme/TOCInline/index.tsx
index 152c076b66..1753f0d4c5 100644
--- a/packages/docusaurus-theme-classic/src/theme/TOCInline/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/TOCInline/index.tsx
@@ -7,7 +7,7 @@
import React from 'react';
import clsx from 'clsx';
-import type {TOCProps} from '@theme/TOC';
+import type {TOCInlineProps} from '@theme/TOCInline';
import styles from './styles.module.css';
import {TOCItem} from '@docusaurus/types';
@@ -39,7 +39,7 @@ function HeadingsInline({
);
}
-function TOCInline({toc}: TOCProps): JSX.Element {
+function TOCInline({toc}: TOCInlineProps): JSX.Element {
return (
diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
index 9e1a1414ac..45396412d0 100644
--- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
@@ -14,7 +14,7 @@ import clsx from 'clsx';
import styles from './styles.module.css';
-function isInViewport(element: HTMLElement) {
+function isInViewport(element: HTMLElement): boolean {
const {top, left, bottom, right} = element.getBoundingClientRect();
const {innerHeight, innerWidth} = window;
@@ -24,7 +24,7 @@ function isInViewport(element: HTMLElement) {
const keys = {
left: 37,
right: 39,
-};
+} as const;
function Tabs(props: Props): JSX.Element {
const {lazy, block, defaultValue, values, groupId, className} = props;
@@ -79,14 +79,16 @@ function Tabs(props: Props): JSX.Element {
let focusElement;
switch (event.keyCode) {
- case keys.right:
+ case keys.right: {
const nextTab = tabRefs.indexOf(event.target) + 1;
focusElement = tabRefs[nextTab] || tabRefs[0];
break;
- case keys.left:
+ }
+ case keys.left: {
const prevTab = tabRefs.indexOf(event.target) - 1;
focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
break;
+ }
default:
break;
}
diff --git a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
index 06e119fdec..48cbac92f4 100644
--- a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
@@ -5,26 +5,32 @@
* LICENSE file in the root directory of this source tree.
*/
-import React, {ComponentProps} from 'react';
+import React, {CSSProperties} from 'react';
import Toggle from 'react-toggle';
+import type {Props} from '@theme/Toggle';
import {useThemeConfig} from '@docusaurus/theme-common';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import clsx from 'clsx';
import styles from './styles.module.css';
-const Dark = ({icon, style}) => (
+interface IconProps {
+ icon: string;
+ style: CSSProperties;
+}
+
+const Dark = ({icon, style}: IconProps): JSX.Element => (
{icon}
);
-const Light = ({icon, style}) => (
+const Light = ({icon, style}: IconProps): JSX.Element => (
{icon}
);
-export default function (props: ComponentProps): JSX.Element {
+export default function (props: Props): JSX.Element {
const {
colorMode: {
switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
diff --git a/packages/docusaurus-theme-classic/src/types.d.ts b/packages/docusaurus-theme-classic/src/types.d.ts
index ba860b2046..db097f87d7 100644
--- a/packages/docusaurus-theme-classic/src/types.d.ts
+++ b/packages/docusaurus-theme-classic/src/types.d.ts
@@ -258,9 +258,43 @@ declare module '@theme/Layout' {
export default Layout;
}
+declare module '@theme/LayoutHead' {
+ import type {Props} from '@theme/Layout';
+
+ const LayoutHead: (props: Props) => JSX.Element;
+ export default LayoutHead;
+}
+
+declare module '@theme/SearchMetadatas' {
+ export type Props = {
+ locale?: string;
+ version?: string;
+ tag?: string;
+ };
+
+ const SearchMetadatas: (props: Props) => JSX.Element;
+ export default SearchMetadatas;
+}
+
+declare module '@theme/LastUpdated' {
+ export type Props = {
+ lastUpdatedAt?: number;
+ formattedLastUpdatedAt?: string;
+ lastUpdatedBy?: string;
+ };
+
+ const LastUpdated: (props: Props) => JSX.Element;
+ export default LastUpdated;
+}
+
+declare module '@theme/SkipToContent' {
+ const SkipToContent: () => JSX.Element;
+ export default SkipToContent;
+}
+
declare module '@theme/MDXComponents' {
- import {ComponentProps} from 'react';
- import CodeBlock from '@theme/CodeBlock';
+ import type {ComponentProps} from 'react';
+ import type CodeBlock from '@theme/CodeBlock';
export type MDXComponentsObject = {
readonly code: typeof CodeBlock;
@@ -465,10 +499,12 @@ declare module '@theme/TOCInline' {
}
declare module '@theme/Toggle' {
- import {ComponentProps} from 'react';
- import ReactToggle from 'react-toggle';
+ import type {ComponentProps} from 'react';
+ import type ReactToggle from 'react-toggle';
- const Toggle: (props: ComponentProps) => JSX.Element;
+ export type Props = ComponentProps;
+
+ const Toggle: (props: Props) => JSX.Element;
export default Toggle;
}
diff --git a/packages/docusaurus-theme-common/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx b/packages/docusaurus-theme-common/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx
index f34215e498..5cf52bd4ce 100644
--- a/packages/docusaurus-theme-common/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx
+++ b/packages/docusaurus-theme-common/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx
@@ -133,7 +133,7 @@ export function DocsPreferredVersionContextProvider({
children,
}: {
children: ReactNode;
-}) {
+}): JSX.Element {
if (isDocsPluginEnabled) {
return (
@@ -149,7 +149,7 @@ function DocsPreferredVersionContextProviderUnsafe({
children,
}: {
children: ReactNode;
-}) {
+}): JSX.Element {
const contextValue = useContextValue();
return {children};
}