Skip to content

Commit 0fbef4c

Browse files
committed
refactor: replace ugly semicolon-prefix type-cast syntax with proper const declarations
Replace ;(x as any).method?.() pattern with cleaner const + conditional check pattern: - Extract type-cast to named const variable - Use explicit if-statement or ternary instead of optional chaining on cast Affected files: - chat.tsx: flushed promise handling - multiline-input.tsx: focus method call - use-clipboard.ts: getSelection call - markdown-renderer.tsx: table row iteration - terminal-color-detection.ts: stream close calls
1 parent f85f16a commit 0fbef4c

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

cli/src/chat.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export const App = ({
237237

238238
const flushed = flushAnalytics()
239239
if (flushed && typeof (flushed as Promise<void>).finally === 'function') {
240-
;(flushed as Promise<void>).finally(() => process.exit(0))
240+
const flushedPromise = flushed as Promise<void>
241+
flushedPromise.finally(() => process.exit(0))
241242
} else {
242243
process.exit(0)
243244
}
@@ -260,7 +261,8 @@ export const App = ({
260261

261262
const flushed = flushAnalytics()
262263
if (flushed && typeof (flushed as Promise<void>).finally === 'function') {
263-
;(flushed as Promise<void>).finally(() => process.exit(0))
264+
const flushedPromise = flushed as Promise<void>
265+
flushedPromise.finally(() => process.exit(0))
264266
} else {
265267
process.exit(0)
266268
}

cli/src/components/multiline-input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ export const MultilineInput = forwardRef<
116116
focus: () => {
117117
const node = scrollBoxRef.current
118118
if (node && typeof (node as any).focus === 'function') {
119-
;(node as any).focus()
119+
const focusableNode = node as any
120+
focusableNode.focus()
120121
}
121122
},
122123
}),

cli/src/hooks/use-clipboard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const useClipboard = () => {
3131

3232
useEffect(() => {
3333
const handleSelection = (selectionEvent: any) => {
34-
const selectionObj = selectionEvent ?? (renderer as any)?.getSelection?.()
34+
const rendererAny = renderer as any
35+
const selectionObj = selectionEvent ?? (rendererAny?.getSelection ? rendererAny.getSelection() : undefined)
3536
const rawText: string | null = selectionObj?.getSelectedText
3637
? selectionObj.getSelectedText()
3738
: typeof selectionObj === 'string'

cli/src/utils/markdown-renderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ const renderTable = (table: Table, state: RenderState): ReactNode[] => {
673673
// Calculate column widths
674674
const columnWidths: number[] = []
675675
table.children.forEach((row) => {
676-
;(row as TableRow).children.forEach((cell, colIdx) => {
676+
const tableRow = row as TableRow
677+
tableRow.children.forEach((cell, colIdx) => {
677678
const cellText = nodeToPlainText(cell as TableCell)
678679
const width = cellText.length
679680
columnWidths[colIdx] = Math.max(columnWidths[colIdx] || 0, width)

cli/src/utils/terminal-color-detection.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ function queryTerminalOSC(oscCode: number): Promise<string | null> {
117117
readStream.removeListener('error', onError)
118118
try {
119119
// Prefer close() so stream owns its FD lifecycle
120-
;(readStream as any).close?.()
120+
const stream = readStream as any
121+
if (stream.close) {
122+
stream.close()
123+
}
121124
} catch {}
122125
cleanup()
123126
resolve(response)
@@ -128,7 +131,10 @@ function queryTerminalOSC(oscCode: number): Promise<string | null> {
128131
readStream.removeListener('data', onData)
129132
readStream.removeListener('error', onError)
130133
try {
131-
;(readStream as any).close?.()
134+
const stream = readStream as any
135+
if (stream.close) {
136+
stream.close()
137+
}
132138
} catch {}
133139
cleanup()
134140
resolve(null)
@@ -146,7 +152,10 @@ function queryTerminalOSC(oscCode: number): Promise<string | null> {
146152
readStream.removeListener('data', onData)
147153
readStream.removeListener('error', onError)
148154
try {
149-
;(readStream as any).close?.()
155+
const stream = readStream as any
156+
if (stream.close) {
157+
stream.close()
158+
}
150159
} catch {}
151160
cleanup()
152161
resolve(null)

0 commit comments

Comments
 (0)