From 83eb0a326a39771d9b9354a9d223d54a1c55052d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 30 May 2024 10:07:59 -0700 Subject: [PATCH] typeahead_helper: Fix TypeScript noUncheckedIndexedAccess errors. Signed-off-by: Anders Kaseorg --- web/src/typeahead_helper.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts index 57cd457cf6..c56e9f28d1 100644 --- a/web/src/typeahead_helper.ts +++ b/web/src/typeahead_helper.ts @@ -58,8 +58,7 @@ export function highlight_with_escaping_and_regex(regex: RegExp, item: string): const pieces = item.split(regex).filter(Boolean); let result = ""; - for (let i = 0; i < pieces.length; i += 1) { - const piece = pieces[i]; + for (const [i, piece] of pieces.entries()) { if (regex.test(piece) && (i === 0 || pieces[i - 1].endsWith(" "))) { // only highlight if the matching part is a word prefix, ie // if it is the 1st piece or if there was a space before it