DEV Community

Discussion on: You should probably learn TypeScript

fjones profile image
FJones • Edited on

I dislike TypeScript because it is highly opinionated, has illegible syntax that puts Regex, Lisp, and Haskell to shame, and because that very frustration with compiler errors leaves my junior devs with a wave of any type declarations just to get it running. Operationally, I find it to be a waste of time in development and code review. It also provides a false sense of security - the belief that a type system solves all of your programming woes. Maybe I'm too used to weakly-typed languages, but I often very much appreciate the flexibility of it, and I find it a lot easier to infer types than to write TS type definitions all day.

As an individual developer, I can appreciate the benefits TypeScript can provide, when done right and when consistently enforced. Contrary to what many people list as their motivator, I think TS is much better suited for small, self-contained projects than for large, growing codebases with a lot of developers of varying skill levels. But as a tech lead, I would rather see improvements to innate programming skill through code review, than through an opinionated tool that frustrates the developer to the point they ask me for help - and ultimately don't really understand it.

Edit: Just to add, yes, obviously I do think at a certain stage everyone vaguely involved with JavaScript should take a dive into TypeScript, just as a means of getting familiar with it and being able to understand it conceptually as well as reading foreign code. But as noted in the OP and my personal conviction: Don't try to push it as the be-all-end-all that must now be used everywhere, even if you like it. Maintainability and team management requires a lot more than a fancy tech stack.

easonsoong profile image

I don't like TypeScript as first because I can not see the value of writing those TS type definitions. And writing and checking those weird TS types and grammer also takes time that should be used for testing my code. But I found it valuable one day when I have to refactor part of my code, it may return some obj that play a role everywhere in my project. After update my code, typescript found some code that has a wrong TS types match, and I can fix that in a few minutes with more confident that I have fixed all the problem. It is worth trying Typescript.

Thread Thread
natescode profile image

Most JavaScript only bootcampers on here won’t like TS at first because it is hard. They lack the experience and knowledge of why static typing is valuable.

JavaScript was designed for non-programmers after all.

natescode profile image

So your junior devs are frustrated that TS is telling them they’re writing bad code? I’m afraid to ask how they handle code reviews then.

bennycode profile image
Benny Neugebauer

Why do you think that TypeScript is opinionated? The development of TypeScript happens in the open source space, so every developer can give his or her input to the design of the language. That actually makes it very transparent and less opinionated.

I don't think that TypeScript provides a false sense of security. Ofcourse, TypeScript cannot help you when you use the compiled code with plain JavaScript because then you are allowed to pass incorrect types to a function. But that's the problem of JavaScript, not TypeScript.

If your junior developers use the any type where it is not needed, it means that they don't have a good overview about your application. This is a good time for you to talk with them about how your application is going to be used and how it should behave.

TypeScript also offers type inference, so there is no need to "write TS type definitions all day". You can read more about it here:

I don't think that TypeScript should be a replacement for code reviews. You need both and TypeScript will actually make your reviews much easier because the compiler will flag already issues to your team mates before they flag them to you.

Again, TypeScript is not just a "fancy" stack. CoffeeScript was a fancy stack but TypeScript provides real value with a real compiler. One of the best things about TypeScript is that you can use it with plain JavaScript code, so you can easily start with it and integrate it slowly in your application. That's perfect for beginners or a migration of an existing code base. You can write the JS code, that you are familiar with, in a file with a ".ts" extension and if you feel experienced enough, you can start using advanced programming techniques und type guards where needed.