TypeScript isNaN only accepts a number

I advise you to implement your code differently.
The reasons:

  1. It might be short, but it’s not easy to understand what’s going on
  2. Using isNaN isn’t the best option here: isNaN("") returns false as well

You better try to convert the value into a number and check if that’s NaN or not (as @smnbbrv wrote):

if (typeof expectedValue === "string" && !Number.isNaN(Number(expectedValue))) {
    expectedValue = Number(expectedValue);
}

Edit

You can pass your value as any:

isNaN(ctualValue as any)

To bypass the compiler check.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)