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 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);

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 3 'function _valuesEqual|sortedA|sortedB' packages/ui/src/TreeSelect.ts
fd -a 'tsconfig*.json' -x rg -n '"strict"\s*:\s*true' '{}'

Repository: Karanjot786/TermUI

Length of output: 713


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the helper and package TypeScript config/package.json metadata without executing repository code.
sed -n '170,195p' packages/ui/src/TreeSelect.ts
printf '\n--- relevant tsconfig files ---\n'
for f in $(fd 'tsconfig.*\.json' .); do
  printf '\n### %s\n' "$f"
  python3 - <<'PY' "$f"
import json, sys
p=sys.argv[1]
try:
    data=json.load(open(p))
except Exception as e:
    print(f"ERR: {e}")
    raise SystemExit(2)
print(p, data.get("compilerOptions", {}).get("strict"))
PY
done

Repository: Karanjot786/TermUI

Length of output: 5161


Use a typed comparator for both sorted arrays.

packages/ui is configured with strict type checking, and a - b on string[] values does not type-check. Sort both sortedA and sortedB with the same numeric-string comparator so values such as ['10', '2'] and ['2', '10'] compare equal.

🤖 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` at line 185, Replace the numeric comparator `a
- b` in the sort function for sortedA with a typed numeric-string comparator
that converts string values to numbers for comparison, then apply the same
comparator to sortedB to ensure both arrays use consistent comparison logic.
This will properly handle numeric string values like '10' and '2' so they
compare correctly in strict type checking mode.

Source: Coding guidelines

const sortedB = [...b].sort();
for (let i = 0; i < sortedA.length; i++) {
if (sortedA[i] !== sortedB[i]) return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function promptSelect<T = string>(options: SelectPromptOptions<T>): Promis
return;
}
const n = parseInt(trimmed, 10);
if (!isNaN(n) && n >= 1 && n <= choices.length) {
if (!Number.isNaN(n) && n >= 1 && n <= choices.length) {
rl.close();
resolve(choices[n - 1].value);
return;
Expand Down
Loading