Skip to content

[non-null] limitless/normalizer.ts: 2 params.start! and params.end! assertions inside guarded callbacks #303

@realfishsam

Description

@realfishsam

Risk Level

MEDIUM

File

core/src/exchanges/limitless/normalizer.ts

Findings

  • Line 74: candles = candles.filter((c) => c.timestamp >= params.start!.getTime()); — inside if (params.start), but TypeScript does not narrow optional properties inside arrow-function callbacks.
  • Line 77: candles = candles.filter((c) => c.timestamp <= params.end!.getTime()); — same issue for params.end.

What Happens When It's Wrong

Logically safe: the if (params.start) / if (params.end) guards on lines 73/76 ensure the values are non-null before entering the block. TypeScript's control-flow analysis does not narrow through closures, so the ! is needed to satisfy the compiler. No runtime crash is expected under current code.

The risk is a future refactor that removes the outer if guard without removing the ! — the assertion silently hides the bug.

Suggested Fix

Capture the value in a local const before the callback so TypeScript can narrow it:

if (params.start) {
    const start = params.start;
    candles = candles.filter((c) => c.timestamp >= start.getTime());
}
if (params.end) {
    const end = params.end;
    candles = candles.filter((c) => c.timestamp <= end.getTime());
}

Found by automated non-null assertion audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions