diff --git a/packages/core/src/search/client.ts b/packages/core/src/search/client.ts index e584de5b8..af3c2e2eb 100644 --- a/packages/core/src/search/client.ts +++ b/packages/core/src/search/client.ts @@ -56,7 +56,7 @@ export function useDocsSearch( const [error, setError] = useState(); const [isLoading, setIsLoading] = useState(false); const debouncedValue = useDebounce(search, delayMs); - const onStart = useRef<() => void>(); + const onStart = useRef<() => void>(undefined); const cacheKey = useMemo(() => { return key ?? JSON.stringify([client.type, debouncedValue, locale, tag]); diff --git a/packages/core/src/toc.tsx b/packages/core/src/toc.tsx index cedd93fac..8c4dfeeda 100644 --- a/packages/core/src/toc.tsx +++ b/packages/core/src/toc.tsx @@ -9,7 +9,9 @@ import { useAnchorObserver } from './utils/use-anchor-observer'; const ActiveAnchorContext = createContext([]); -const ScrollContext = createContext>({ current: null }); +const ScrollContext = createContext>({ + current: null, +}); /** * The estimated active heading ID @@ -40,7 +42,7 @@ export interface ScrollProviderProps { /** * Scroll into the view of container when active */ - containerRef: RefObject; + containerRef: RefObject; children?: ReactNode; } diff --git a/packages/core/src/utils/use-debounce.ts b/packages/core/src/utils/use-debounce.ts index 75c8d64a0..a0db1f4f6 100644 --- a/packages/core/src/utils/use-debounce.ts +++ b/packages/core/src/utils/use-debounce.ts @@ -2,7 +2,7 @@ import { useRef, useState } from 'react'; export function useDebounce(value: T, delayMs = 1000): T { const [debouncedValue, setDebouncedValue] = useState(value); - const timer = useRef<{ value: T; handler: number }>(); + const timer = useRef<{ value: T; handler: number } | undefined>(undefined); if (delayMs === 0) return value; diff --git a/packages/core/src/utils/use-shiki.tsx b/packages/core/src/utils/use-shiki.tsx index 03a9b63f2..904983db5 100644 --- a/packages/core/src/utils/use-shiki.tsx +++ b/packages/core/src/utils/use-shiki.tsx @@ -20,8 +20,9 @@ export function useShiki( ): ReactNode { const [out, setOut] = useState(() => { if (options.defaultValue) return options.defaultValue; + const Pre = (options.components?.pre ?? 'pre') as 'pre'; + const Code = (options.components?.code ?? 'code') as 'code'; - const { pre: Pre = 'pre', code: Code = 'code' } = options.components ?? {}; return (
         {code}
diff --git a/packages/openapi/src/render/markdown.tsx b/packages/openapi/src/render/markdown.tsx
index eee82ef8f..8156ab216 100644
--- a/packages/openapi/src/render/markdown.tsx
+++ b/packages/openapi/src/render/markdown.tsx
@@ -33,7 +33,6 @@ export async function Markdown({
     jsx: jsx as Jsx,
     jsxs: jsxs as Jsx,
     Fragment,
-    // @ts-expect-error -- safe to use
     components: defaultMdxComponents,
   });
 }
diff --git a/packages/twoslash/src/ui/popup.tsx b/packages/twoslash/src/ui/popup.tsx
index 7848cef7e..bc0170307 100644
--- a/packages/twoslash/src/ui/popup.tsx
+++ b/packages/twoslash/src/ui/popup.tsx
@@ -24,10 +24,10 @@ function Popup({
 }: {
   delay?: number;
   children: React.ReactNode;
-}): JSX.Element {
+}) {
   const [open, setOpen] = useState(false);
-  const openTimeoutRef = useRef();
-  const closeTimeoutRef = useRef();
+  const openTimeoutRef = useRef(undefined);
+  const closeTimeoutRef = useRef(undefined);
 
   const handleOpen = (e: React.PointerEvent): void => {
     if (e.pointerType === 'touch') return;
@@ -86,7 +86,7 @@ const PopupTrigger = forwardRef<
 PopupTrigger.displayName = 'PopupTrigger';
 
 const PopupContent = forwardRef<
-  React.ElementRef,
+  React.ComponentRef,
   React.ComponentPropsWithoutRef
 >((props, ref) => {
   const ctx = useContext(PopupContext);
diff --git a/packages/typescript/src/ui/auto-type-table.tsx b/packages/typescript/src/ui/auto-type-table.tsx
index c2a13488a..1552e8a01 100644
--- a/packages/typescript/src/ui/auto-type-table.tsx
+++ b/packages/typescript/src/ui/auto-type-table.tsx
@@ -129,7 +129,6 @@ async function renderMarkdown(md: string): Promise {
     Fragment: runtime.Fragment,
     jsx: runtime.jsx as Jsx,
     jsxs: runtime.jsxs as Jsx,
-    // @ts-expect-error -- mdx components
     components: { ...defaultMdxComponents, img: undefined },
   });
 }
diff --git a/packages/ui/src/components/dialog/search.tsx b/packages/ui/src/components/dialog/search.tsx
index a40901821..8d5a21cc4 100644
--- a/packages/ui/src/components/dialog/search.tsx
+++ b/packages/ui/src/components/dialog/search.tsx
@@ -153,8 +153,7 @@ function SearchList({ items, hideResults = false }: SearchResultProps) {
     setActive(items[0].id);
   }
 
-  const listenerRef = useRef<(e: KeyboardEvent) => void>();
-  listenerRef.current = (e) => {
+  function onKey(e: KeyboardEvent) {
     if (e.key === 'ArrowDown' || e.key == 'ArrowUp') {
       setActive((cur) => {
         const idx = items.findIndex((item) => item.id === cur);
@@ -174,12 +173,13 @@ function SearchList({ items, hideResults = false }: SearchResultProps) {
       if (selected) onOpen(selected.url);
       e.preventDefault();
     }
-  };
+  }
+
+  const listenerRef = useRef(onKey);
+  listenerRef.current = onKey;
 
   useEffect(() => {
-    const listener = (e: KeyboardEvent) => {
-      listenerRef.current?.(e);
-    };
+    const listener = (e: KeyboardEvent) => listenerRef.current?.(e);
 
     window.addEventListener('keydown', listener);
     return () => {
diff --git a/packages/ui/src/components/layout/toc-thumb.tsx b/packages/ui/src/components/layout/toc-thumb.tsx
index 599b5d62c..571c65353 100644
--- a/packages/ui/src/components/layout/toc-thumb.tsx
+++ b/packages/ui/src/components/layout/toc-thumb.tsx
@@ -44,7 +44,7 @@ export function TocThumb({
   containerRef,
   ...props
 }: HTMLAttributes & {
-  containerRef: RefObject;
+  containerRef: RefObject;
 }): ReactNode {
   const active = Primitive.useActiveAnchors();
   const thumbRef = useRef(null);
diff --git a/packages/ui/src/components/tabs.tsx b/packages/ui/src/components/tabs.tsx
index bc8e172cc..d4b46bdd2 100644
--- a/packages/ui/src/components/tabs.tsx
+++ b/packages/ui/src/components/tabs.tsx
@@ -73,12 +73,13 @@ export function Tabs({
   const values = useMemo(() => items.map((item) => toValue(item)), [items]);
   const [value, setValue] = useState(values[defaultIndex]);
   const valueToIdMapRef = useRef(new Map());
-  const onChangeRef = useRef();
-
-  onChangeRef.current = (v) => {
+  const onChange: ChangeListener = (v) => {
     if (values.includes(v)) setValue(v);
   };
 
+  const onChangeRef = useRef(onChange);
+  onChangeRef.current = onChange;
+
   useLayoutEffect(() => {
     if (!groupId) return;
     const onUpdate: ChangeListener = (v) => onChangeRef.current?.(v);