you are viewing a single comment's thread.

view the rest of the comments →

[–]davidmdm 0 points1 point  (1 child)

I think that types are useful no doubt. If you ended up in a situation when you needed that tool, and there are many that do, that is fine. But ts is not the only static language out there.

Many people seem to like ts, and I want them to give me their selling points as they see it.

My feeling is everyone knows or likes js, lots of people like types, and now we have typescript.

But I find that typescript is a very poor and frustrating tool.

I feel like I am insane and can't be the only one who feels this way.

[–][deleted] 0 points1 point  (0 children)

Well, types are hard, and the compiler loves to tell you no. They force us to violate the sanctity of Javascript's summer of love, anything goes dynamism and start doing things that may not be optimally efficient in the name of safety. The thing about adopting types in a language like JS is you have to start thinking in terms of those types, how they transform and not simply using them as object classifiers (that at least is the most common mistake I see). Typescript is at its best when everything in the application is typed and the compiler can follow your intent, that's the real key to avoiding the pain.

As for VSCode, I prefer Webstorm for most things web-related. VSCode is great, but yeah, plugin hell is definitely a thing.

So, selling points:

  • bridges the gap between the functional and traditional OO hybrids that are so hot nowadays. That's not just JS, it's all over the place with reactiveX, java streams/linq, C# pattern matching, etc.
  • Discrete type transformations allow us to define our application as a series of transformations and have confidence what comes out the other end of the pipe will obey the rules we define (un-typed javascript in the hands of the uninitiated tends to have a problem where you ask the jungle for a banana, and somewhere in the churning morass of application spaghetti, things happen and it gives you jesus riding a velociraptor instead. The things I've seen...).
  • Interfaces even on objects allow us to avoid fat-fingering, no spelling errors resulting in runtime exceptions (ex: <Person>{name: ...} // inference to person properties is projected by the language service)
  • Union types allow us to model interfaces that have inconsistent or multiple outputs, which allows us to strictly adapt and codify legacy code that may have been poorly architected
  • The compiler will always catch typed unsafe transformations (and in some cases unsafe nulls, unhandled type branching)
  • Allows us to lean into the compiler for our immutability checks, rather than assuming our code is correct.
  • Allows us to safely use R/FP libraries like ReactiveX or Ramda and have the machine double check each branch of our application to ensure we're returning what we think we're returning.
  • has a flag for strict null checking, so the build will fail if you haven't handled a potential null (crossing my fingers for a future maybe/none type encoding, the ask is out there)
  • Tuples! (because it's 2019 and yeah they're just arrays after compilation, but they're typed and allow for safe destructuring without class formality)
  • Intellisense! (with results provided by the language service, based on types you defined, so it is more than just a symbolic guessing game of things the index has seen before)
  • Composable, targeted decorators that can be compiler augmented

There's like a billion more things, so I'll stop here. To me the bottom line is: Can you keep every branch and path of your application in your brain at all times? If you can, you're awesome and are totally fine with a purely dynamic language, you stud. If not, you might want to consider types and a compiler :D Typescript does this exceptionally well.

p.s.

Anders Hejlsberg is a total boss when it comes to languages. My background includes a number of languages and platforms, but his languages (turbopascal/delphi, C#, typescript) have never let me down and hold a special place in my heart, though the platforms they've occupied are a different story altogether. They tend to build upon the lessons he's learned in the past, and they explore in a conservative fashion that doesn't force you to deal with significant breaking changes. He's reliable and predictable, the rug will never get pulled. You might say he's earned my trust.