HackerTrans
TopNewTrendsCommentsPastAskShowJobs

unstable

no profile record

comments

unstable
·hace 2 años·discuss
Accepting NaN as a number can potentially crash your app, that's why I reject it in isNumber.

I only tried to highlight some edge cases that I personally don't like to spend energy on, trying to get it right, when writing code. Btw, isNumber is a dynamic call in the example and unrelated to TypeScript. TypeScript doesn't exist at runtime.
unstable
·hace 2 años·discuss
> You can write isNumber(foo) instead of typeof foo === "number".

Indeed you can, but it depends what isNumber does. This is more like what it should do IMO:

function isNumber( foo ) { return ( (typeof foo === "number") && (foo == foo)) || ((typeof foo === 'object') && (foo instanceof Number) ); }

And that is I think the value of micro libs, at least in JS, you don't want to think about all the edge cases when you only want to check if something is a Number.
unstable
·hace 2 años·discuss
> while the whole thing should be on the editor's side.

This.

I'd prefer using my own preferences instead of using a dumb formatter like prettier. Who cares some other dev in your team prefers 2 chars indentation? It should be an editor preference, not applied to source code.

Personally I would also prefer the IDE to do type checking as well so we can get rid of the TypeScript misery, but that's another discussion.
unstable
·hace 2 años·discuss
Thanks for the links, awesome!