Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/showcase/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ShowcaseApp extends Widget {
if (event.key === 'q' || (event.ctrl && event.key === 'c')) return false;

// Tab switching: 1-5
const num = parseInt(event.key);
const num = parseInt(event.key, 10);
if (num >= 1 && num <= 5) {
this.switchTab(num - 1);
return true;
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class WidgetGalleryApp extends Widget {
}

// Tab switching: 1-6
const num = parseInt(event.key);
const num = parseInt(event.key, 10);
if (num >= 1 && num <= 6) {
this._switchTab(num - 1);
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Switch extends Widget {
if (width <= 0) return;

const attrs = styleToCellAttrs(this.style);
const knobPos = Math.round(this._animProgress * 2);
const knobPos = Math.round(this._animProgress * 2 + Number.EPSILON);
const transitioning = this._animProgress > 0 && this._animProgress < 1;

let trackChars: string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/TreeSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function _pathsEqual(a: number[], b: number[]): boolean {

function _valuesEqual(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false;
const sortedA = [...a].sort();
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].sort();
Comment on lines +185 to 186

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 'function _valuesEqual|sortedA|sortedB' packages/ui/src/TreeSelect.ts

while IFS= read -r file; do
  echo "== $file =="
  rg -n -C 2 '"strict"|"noImplicitAny"|"extends"|"include"' "$file" || true
done < <(fd -a 'tsconfig.*\.json$' .)

Repository: Karanjot786/TermUI

Length of output: 600


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== TreeSelect relevant section =="
sed -n '170,192p' packages/ui/src/TreeSelect.ts

echo
echo "== TypeScript config files =="
git ls-files '*tsconfig*.json' | while IFS= read -r file; do
  echo "-- $file --"
  sed -n '1,220p' "$file"
done

echo
echo "== tsconfig strict flags references =="
rg -n '"strict"|"extends"|"include"|"compilerOptions"' $(git ls-files '*tsconfig*.json') || true

echo
echo "== Read-only behavior probe for _valuesEqual with ['2','10'] and ['10','2'] =="
node - <<'JS'
function valuesEqual(a, b) {
  const sortedA = [...a].sort((a, b) => a - b);
  const sortedB = [...b].sort();
  if (a.length !== b.length) return false;
  for (let i = 0; i < sortedA.length; i++) {
    if (sortedA[i] !== sortedB[i]) return false;
  }
  return true;
}
console.log(JSON.stringify({
  inputA: ['2', '10'],
  inputB: ['10', '2'],
  equal: valuesEqual(['2', '10'], ['10', '2'])
}));
JS

Repository: Karanjot786/TermUI

Length of output: 26059


Use a typed numeric comparator for both array sorts.

packages/ui/tsconfig.json enables strict, so subtracting the string[] elements in sortedA.sort((a, b) => a - b) is a type error. sortedB.sort() also does default lexicographic sorting, so ['2', '10'] and ['10', '2'] are treated as unequal.

Proposed fix
-    const sortedA = [...a].sort((a, b) => a - b);
-    const sortedB = [...b].sort();
+    const compareNumeric = (left: string, right: string): number =>
+        Number(left) - Number(right);
+    const sortedA = [...a].sort(compareNumeric);
+    const sortedB = [...b].sort(compareNumeric);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].sort();
const compareNumeric = (left: string, right: string): number =>
Number(left) - Number(right);
const sortedA = [...a].sort(compareNumeric);
const sortedB = [...b].sort(compareNumeric);
🧰 Tools
🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 185-185: TypeScript TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. The DTS build failed while running 'tsup'.


[error] 185-185: TypeScript TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. The DTS build failed while running 'tsup'.

🪛 GitHub Actions: CI / build-and-test

[error] 185-185: TypeScript DTS build failed: the left-hand side of an arithmetic operation must be any, number, bigint, or an enum type (TS2362), and the right-hand side must satisfy the same requirement (TS2363). Failed command: bun run build (tsup).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/TreeSelect.ts` around lines 185 - 186, Update the sortedA and
sortedB sort calls to use a typed numeric comparator that converts each string
element to a number before subtraction. Ensure both arrays use numeric ordering
so equivalent values such as “2” and “10” compare consistently under strict
TypeScript checking.

Source: Coding guidelines

for (let i = 0; i < sortedA.length; i++) {
if (sortedA[i] !== sortedB[i]) return false;
Expand Down
Loading