Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If s is a non-integer number


I mean, that could be changed.

Currently: either string OR number

Possible: either string | number OR just number


> The OR doesn't indicate | in TypeScript, it indicates the result of the possible future type guard.

Are you implying in your other comment (that HN won't let me reply to) that Typescript has an "OR" operator that is distinct from "|"? Can you link to documentation on that?


"OR" was just my (bad) way to explain it. In plain English:

if isInteger(x) is true, x is definitely a `number`

if isInteger(x) is false, x is unknown/unaltered (it remains `typeof x`)

Current type guards can't express "yes versus maybe", so isInteger cannot be a type guard at all.


"string | number | number" is just "string | number" to Typescript.


The OR doesn't indicate | in TypeScript, it indicates the result of the possible future type guard.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: