TypeScript protects from edge cases
TypeScript protects from edge cases.
Example: I reference something that may be undefined.
In JS, I get a runtime error, but only if I happen to execute that particular line. Risky. 😕
In TS, I get a compile error. I can't overlook my mistake. 👍
#typescript
Another example: I accidentally invoke a function when passing it as an argument.
JS: Invokes the function. This may take a while to debug - I may receive no runtime error.
TS: Displays a compile-time error and specifies the line number where I made a mistake. 🙂