DEV Community

Discussion on: TypeScript -- why not?

Collapse
 
curtisfenner profile image
Curtis Fenner

TypeScript doesn't attempt to "hide the JS ugliness" -- TypeScript has exactly the same runtime semantics as JavaScript. It's impossible to learn TypeScript without also learning JavaScript, and since valid JavaScript is truly a subset of TypeScript, if you have learned JavaScript you have also learned TypeScript.

The version history of JavaScript, idiosyncratic standard library, the way prototypes and inheritance works, automatic conversions, etc. are all components of TypeScript, because all JavaScript is also TypeScript.

The purpose of TypeScript is to manage complexity. Machine-checked types let you communicate faster:

  • You can suddenly communicate with the IDE, since the IDE now understands what properties and methods are available (e.g., auto-completion), and what arguments are legal and illegal (e.g., oops, this argument isn't nullable, or you typo'd an enum value in your configuration)
  • You can communicate with other developers faster than without types:
    • Comments can lie, types don't (as often) -- you don't have to double check things, because the compiler has double checked them for you
    • The type signature is dramatically shorter than the implementation, so you can just read that and use the module written by someone else, instead of the extensive code or docs
    • Many/most type-signatures are inferred, so they're "there" without the writer needing to actually embed them in the source code -- this is like getting documentation for your functions being written for free

And, they can also speed up development, because they can give you a clearer direction forward. Just like writing tests up front can help ensure you're only writing functions that actually solve your problems, writing types up front can ensure you're actually covering all of the surface area in a way that encourages callers to "fall into the pit of success".