filter: 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 beef5d259b
commit da7d8b902b
1 changed files with 2 additions and 1 deletions

View File

@ -581,7 +581,7 @@ export class Filter {
return parts; return parts;
} }
if (terms.length >= 2) { if (terms[0] !== undefined && terms[1] !== undefined) {
const is = (term: NarrowTerm, expected: string): boolean => const is = (term: NarrowTerm, expected: string): boolean =>
Filter.canonicalize_operator(term.operator) === expected && !term.negated; Filter.canonicalize_operator(term.operator) === expected && !term.negated;
@ -1151,6 +1151,7 @@ export class Filter {
filter_with_new_params(params: NarrowTerm): Filter { filter_with_new_params(params: NarrowTerm): Filter {
const new_params = this.fix_terms([params])[0]; const new_params = this.fix_terms([params])[0];
assert(new_params !== undefined);
const terms = this._terms.map((term) => { const terms = this._terms.map((term) => {
const new_term = {...term}; const new_term = {...term};
if (new_term.operator === new_params.operator && !new_term.negated) { if (new_term.operator === new_params.operator && !new_term.negated) {