In my life as a developer I tried to understand why people want to make certain choices for languages and tools. I don’t want to go pick a tool or language just because people order me to do that. I always wonder why they do that. Is it policy or is did they actually think of it.
I mean I understand why people want to use Typescript from certain perspectives.
• The use of types,
• My framework uses typescript (Eg. Angular),
• The ease of use of OOP programming,
• My Java developers can immediately start programming because of the familiarity Typescript has with Java,
• Typescript allows me to use my tooling like autocompletion,
Of all these arguments I can just as easily say a counter argument. For me the only really valid point is the second argument in above list.
When you choose a framework where all the documentation is written in a language it is hard to break out of that language.
Let me try to explain why I am not convinced in these arguments.
In using good programming (mind you I say programming not Typescript) we make use of Types (often seen as objects in OOP).Types are defined by a contract not by using a keyword that loses its purpose in runtime.
I like dynamic languages. The give me an feeling of productivity that I cannot achieve with statically typed languages like Java (or Typescript).
I like to work with the mantra:
if it walks like a duck and if it talks like a duck, it's probably a duck
For me this is all about the contract.
When the object in question does not follow the contract it just isn't the type we need in this context. If we use Typescript to define our types we know it is fine during compilation however in runtime there is no such confirmation or construct that we are using the expected type. The only way to way to verify this is to test.
Why do I say we have no such confirmation in runtime? Well too often I see developers make use of the 'any' type. 'any' basically says: I don't know what type we're using here but trust me it's gonna be alright.... ?
This 'any' and the loosing of typing in runtime can give us false safety.
*Update november 27th 2021,
The latest versions of Typescript have undergone some much improved additions to the typesystem. This makes the use of types much stronger and I dare say even better as you can no even use types (to some degree) in such a way it will contain logic that foregoes the use of unit tests. This means the compiler is able to apply logic to the output of some functions so the functions no longer need to be tested. I even saw a usage of this that is able to solve sudokus at compile-time. Though this seems great it costs a whole lot of understanding new ways to solving solutions programatically. The complexity is really big when using this approach and leads to other costs during development. Eric Elliott calls this
Typing overhead. In my opinion if you really want to use typesafety in your web development you should thing of languages like ReScript. ReScript offers typing but due to superb type-inference you will hardly notice this when creating your code, but your IDE and compiler will still be able to confirm to your used types.
Currently amongst the most used frameworks in the enterprise is Angular. Angular is written in Typescript. All the documentation is written in Typescript. All the examples likewise. I understand this as a valid point in using Typescript. It makes your productivity much higher especially when you program and use the likes as stack overflow and the official examples as your way to solve your programming issues. No questions asked no answers given. I take this as fact. However, I still wonder why these frameworks would be written in Typescript in the first place.
In fact ES6 offers this construct so it is not even exclusive to Typescript.
Now I favor the use of functional programming over oop, while this is not entirely so. I really prefer the use of a hybrid approach of using both functional and oop in my code.
I see the use of services best described in a functional pattern, not in the way Java promotes. Java services are often a collection of related methods combined in an object. To me this is more or less a Façade without the usage of multiple delegated extra components.
Coming from a different language
I heard a few of my peers tell me: "well thanks to Typescript my java developers were able to code for the frontend because the language is practically the same."
There is so much wrong with this argumentation, I hardly know where to begin. Let me try though.
Being able to program in another language because the syntax is so familiar is like saying you can use oranges for your apple pie because they are both fruits and hang both on a tree and you have to peel their skin off.
Go and tell an average Java programmer to start programming in C# because the syntax is nearly the same. It just doesn't work that way. Sure the programmer is able to produce some code, but let's call it at that ok? Tell a windows engineer to setup a linux server, they are both servers and have a cli. I think you got my meaning.
We hide the concept of the actual workings of prototypal inheritance in Typescript or even in ES6 for that matter. The interface semantics are different in Typescript than in Java. In Java an interface is meant to be a contract, in Typescript it is meant as a struct a type without any specific behaviour. Though the documentation claims the interface to be a contract as well, I even see this construct in a Typescript interface:
[propertyName: string]: any;
What this allows you to do, is to basically say: any property you add to this interface is allowed.
Object literal? Any? (pun intended).
We basically leave the contract so wide open it basically becomes void.
I just think you just need to take the fear of using a different language away from the Java developer Typescript is just another trick to persuade the Java developer to become a frontend developer, but it leaves the developer in no-mans land.
Typescript allows me to use tooling for my productivity.
Personally I have a multitude of tools I write my code in. I am a vim user (neovim for that matter). I have found lots of ways to increase my productivity in that editor.
Do I want to be convinced to use Typescript?
I would be very happy if someone could point out to me what I am missing. I want to share knowledge and I certainly will try to provide this found knowledge to others in helping them.
For references I also direct you too these documents