Skip to content

Commit 2f90799

Browse files
codydeclaude
andcommitted
Fix TypeScript linting errors across components
- Fix RefObject type errors by updating function signatures to accept null - Add proper type guards with isValidElement for React element checks - Replace JSX.Element with ReactElement imports - Fix ToggleEventHandler type mismatch in expandable component - Add missing attributes property to ImportDeclaration type - Use optional chaining for safer property access 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b0dda5c commit 2f90799

File tree

8 files changed

+33
-22
lines changed

8 files changed

+33
-22
lines changed

src/clientUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type ClickOutsideCallback = (event: MouseEvent) => void;
44

55
interface UseClickOutsideOpts<E extends HTMLElement> {
66
handler: ClickOutsideCallback;
7-
ref: React.RefObject<E>;
7+
ref: React.RefObject<E | null>;
88
enabled?: boolean;
99
}
1010

src/components/codeBlock/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function cleanCodeSnippet(rawCodeSnippet: string, options?: CleanCopyOpti
119119
* @param options - Configuration options for cleaning
120120
*/
121121
export function useCleanSnippetInClipboard(
122-
codeRef: RefObject<HTMLElement>,
122+
codeRef: RefObject<HTMLElement | null>,
123123
options: CleanCopyOptions = {}
124124
) {
125125
const {cleanDiffMarkers = true, cleanBashPrompt = true, language = ''} = options;

src/components/codeHighlights/codeHighlights.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import {Children, cloneElement, ReactElement, useEffect, useRef, useState} from 'react';
3+
import {Children, cloneElement, ReactElement, useEffect, useRef, useState, isValidElement} from 'react';
44
import {Check, Clipboard} from 'react-feather';
55
import styled from '@emotion/styled';
66
import * as Sentry from '@sentry/nextjs';
@@ -19,20 +19,20 @@ export function makeHighlightBlocks(
1919
let highlightElementGroupCounter = 0;
2020

2121
return items.reduce((arr: ChildrenItem[], child, index) => {
22-
if (typeof child !== 'object') {
22+
if (typeof child !== 'object' || !isValidElement(child)) {
2323
arr.push(child);
2424
return arr;
2525
}
2626

2727
const element = child as ReactElement;
28-
const classes = element.props.className;
28+
const classes = element.props?.className;
2929

3030
const isCodeLine = classes && classes.includes('code-line');
3131
if (!isCodeLine) {
3232
const updatedChild = cloneElement(
33-
child as ReactElement,
33+
element,
3434
element.props,
35-
makeHighlightBlocks((child as ReactElement).props.children, language)
35+
makeHighlightBlocks(element.props?.children, language)
3636
);
3737
arr.push(updatedChild);
3838
return arr;

src/components/codeKeywords/codeKeywords.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import {Children, cloneElement, ReactElement} from 'react';
3+
import {Children, cloneElement, ReactElement, isValidElement} from 'react';
44

55
import {KeywordSelector} from './keywordSelector';
66
import {OrgAuthTokenCreator} from './orgAuthTokenCreator';
@@ -15,19 +15,24 @@ export function makeKeywordsClickable(children: React.ReactNode) {
1515
const items = Children.toArray(children);
1616

1717
return items.reduce((arr: ChildrenItem[], child) => {
18-
if (typeof child !== 'string') {
18+
if (typeof child !== 'string' && isValidElement(child)) {
19+
const element = child as ReactElement;
1920
const updatedChild = cloneElement(
20-
child as ReactElement,
21+
element,
2122
{},
22-
makeKeywordsClickable((child as ReactElement).props.children)
23+
makeKeywordsClickable(element.props?.children)
2324
);
2425
arr.push(updatedChild);
2526
return arr;
2627
}
27-
if (ORG_AUTH_TOKEN_REGEX.test(child)) {
28-
makeOrgAuthTokenClickable(arr, child);
29-
} else if (KEYWORDS_REGEX.test(child)) {
30-
makeProjectKeywordsClickable(arr, child);
28+
if (typeof child === 'string') {
29+
if (ORG_AUTH_TOKEN_REGEX.test(child)) {
30+
makeOrgAuthTokenClickable(arr, child);
31+
} else if (KEYWORDS_REGEX.test(child)) {
32+
makeProjectKeywordsClickable(arr, child);
33+
} else {
34+
arr.push(child);
35+
}
3136
} else {
3237
arr.push(child);
3338
}

src/components/codeTabs.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useEffect,
99
useRef,
1010
useState,
11+
isValidElement,
1112
} from 'react';
1213
import styled from '@emotion/styled';
1314

@@ -45,7 +46,11 @@ const showSigninNote = (children: ReactNode) => {
4546
if (typeof node === 'string') {
4647
return KEYWORDS_REGEX.test(node) || ORG_AUTH_TOKEN_REGEX.test(node);
4748
}
48-
return showSigninNote((node as ReactElement).props.children);
49+
if (isValidElement(node)) {
50+
const element = node as ReactElement;
51+
return showSigninNote(element.props?.children);
52+
}
53+
return false;
4954
});
5055
};
5156

src/components/configValue.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {Fragment} from 'react';
1+
import {Fragment, ReactElement} from 'react';
22

33
type Props = {
4-
children: JSX.Element;
4+
children: ReactElement;
55
location: string;
66
name: string;
77
};
88

9-
const getDescriptiveLocation = (location: string): JSX.Element => {
9+
const getDescriptiveLocation = (location: string): ReactElement => {
1010
switch (location) {
1111
case 'env':
1212
return <Fragment>in System Environment</Fragment>;
@@ -29,7 +29,7 @@ const getDescriptiveLocation = (location: string): JSX.Element => {
2929
}
3030
};
3131

32-
export function ConfigValue({name, location, children}: Props): JSX.Element {
32+
export function ConfigValue({name, location, children}: Props): ReactElement {
3333
return (
3434
<div style={{marginBottom: '2rem'}}>
3535
<h4 style={{marginBottom: 0, fontWeight: 'bold'}}>

src/components/expandable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function Expandable({
134134
[emit, title]
135135
);
136136

137-
function toggleIsExpanded(event: React.MouseEvent<HTMLDetailsElement>) {
137+
function toggleIsExpanded(event: React.SyntheticEvent<HTMLDetailsElement>) {
138138
const newVal = event.currentTarget.open;
139139
setIsExpanded(newVal);
140140

src/components/sidebar/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {ReactElement} from 'react';
12
import {
23
extractPlatforms,
34
getCurrentGuide,
@@ -22,7 +23,7 @@ const activeLinkSelector = `.${styles.sidebar} .toc-item .active`;
2223

2324
export const sidebarToggleId = styles['navbar-menu-toggle'];
2425

25-
export async function Sidebar({path, versions}: SidebarProps): Promise<JSX.Element> {
26+
export async function Sidebar({path, versions}: SidebarProps): Promise<ReactElement> {
2627
const rootNode = await getDocsRootNode();
2728

2829
if (isDeveloperDocs) {

0 commit comments

Comments
 (0)