From f228ec29eb55adca150423549bf5134890095aac Mon Sep 17 00:00:00 2001 From: juju Date: Wed, 23 Oct 2024 18:02:52 +0200 Subject: [PATCH] Enable ts-strict for editAttention.ts (#1269) * fix typecheck errors * revert tsconfig strict true --- src/extensions/core/editAttention.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/extensions/core/editAttention.ts b/src/extensions/core/editAttention.ts index a9f05b95d..2fb288e4e 100644 --- a/src/extensions/core/editAttention.ts +++ b/src/extensions/core/editAttention.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { app } from '../../scripts/app' // Allows you to edit the attention weight by holding ctrl (or cmd) and using the up/down arrow keys @@ -18,14 +17,22 @@ app.registerExtension({ defaultValue: 0.05 }) - function incrementWeight(weight, delta) { + function incrementWeight(weight: string, delta: number): string { const floatWeight = parseFloat(weight) if (isNaN(floatWeight)) return weight const newWeight = floatWeight + delta return String(Number(newWeight.toFixed(10))) } - function findNearestEnclosure(text, cursorPos) { + type Enclosure = { + start: number + end: number + } + + function findNearestEnclosure( + text: string, + cursorPos: number + ): Enclosure | null { let start = cursorPos, end = cursorPos let openCount = 0, @@ -38,7 +45,7 @@ app.registerExtension({ if (text[start] === '(') openCount++ if (text[start] === ')') closeCount++ } - if (start < 0) return false + if (start < 0) return null openCount = 0 closeCount = 0 @@ -50,12 +57,12 @@ app.registerExtension({ if (text[end] === ')') closeCount++ end++ } - if (end === text.length) return false + if (end === text.length) return null return { start: start + 1, end: end } } - function addWeightToParentheses(text) { + function addWeightToParentheses(text: string): string { const parenRegex = /^\((.*)\)$/ const parenMatch = text.match(parenRegex)