filter cannot narrow on its own — it returns the same element type unless the callback is a type predicate. Write one:
TypeScript 5.5+ can infer this automatically when the predicate is a simple, directly-returned comparison, so on a recent compiler your original code may already narrow. If it doesn't, the explicit annotation always works.