Use Number.isNaN instead of global isNaN for type safety - #1234
Use Number.isNaN instead of global isNaN for type safety#1234pavankumar-vh wants to merge 1 commit into
Conversation
The global isNaN() function coerces non-numbers to numbers first, which can
lead to unexpected results. For example, isNaN('hello') returns true because
'hello' is coerced to NaN, but Number.isNaN('hello') returns false because
'hello' is not a number type.
Using Number.isNaN is more predictable and safer for type checking.
|
Good, minimal, focused change. One nit: the PR description overstates the bug ( No tests needed for a one-line safe swap like this. Fine as-is. |
Overview
Fix type safety issue in
common/src/util/log-ingest.tsby usingNumber.isNaNinstead of the globalisNaNfunction.Bug Description
The global
isNaN()function coerces non-numbers to numbers first, which can lead to unexpected results. For example,isNaN('hello')returnstruebecause'hello'is coerced toNaN, butNumber.isNaN('hello')returnsfalsebecause'hello'is not a number type.Fix
Changed
isNaN(ts.getTime())toNumber.isNaN(ts.getTime())for more predictable and safer type checking.Testing
No existing tests for this function, but the fix improves type safety.
Files Changed
common/src/util/log-ingest.ts- Use Number.isNaN instead of global isNaNScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.