I ran into an interesting and silly issue today. First, I invite you to form your own opinion about the following block of code.
source: https://github.com/microsoft/TypeScript/blob/main/lib/lib.es5.d.ts, line 53
/**
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
* @param number A numeric value.
*/
declare function isNaN(number: number): Boolean;
Go ahead — stare at it for a bit. Think about what this function is supposed to do. Read the commented description again. Then stare at it some more. At this point, I’m scratching my head and second guessing myself, with a “What the heck?” thrown in for good measure.
If you haven’t figured out my point yet, consider this: A rock doesn’t need proof that it’s a rock. It simply is. So… if logic serves… why would I need to test a number to see if it’s a number? Kind of defeats the whole purpose, don’t you think?
For you JavaScript purists out there, I get it: There are a thousand ways to write a number in JS. HOWEVER, with Typescript’s “strong typing”, the function ONLY accepts a number. So then what is the point of this function? Exactly — the purpose has been negated. In its current state, this function can only EVER return true. So, pointless.
I figure when I get some time I’ll create a pull request to fix this interface and function, because this is just silly. Please, feel free to beat me to it. Because this is not a good reason to use @ts-ignore.
Like this:
Like Loading...