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
Risk Level
MEDIUM
File
core/src/exchanges/limitless/normalizer.tsFindings
candles = candles.filter((c) => c.timestamp >= params.start!.getTime());— insideif (params.start), but TypeScript does not narrow optional properties inside arrow-function callbacks.candles = candles.filter((c) => c.timestamp <= params.end!.getTime());— same issue forparams.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
ifguard without removing the!— the assertion silently hides the bug.Suggested Fix
Capture the value in a local
constbefore the callback so TypeScript can narrow it:Found by automated non-null assertion audit