typeahead_helper: Fix TypeScript noUncheckedIndexedAccess errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-30 10:07:59 -07:00
parent d0a03be8e0
commit 83eb0a326a
1 changed files with 1 additions and 2 deletions

View File

@ -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