Hm. Problém je toto:
As explained by Eric Elliot in the following great article,
“static types do not reduce overall bug density”.
Types are written by the developers and not checked at runtime, so the “strength” of your program depends on your usage of TypeScript.
If you looking at TypeScript to reduce your bugs, please look at TDD instead.
Alebo od iného autora:
One thing that many beginners do not understand about TypeScript is that it does not guarantee type-correctness at runtime. Your TypeScript code might be fully typed and the compiler ensures you that everything must be correct… but at runtime you still get errors because your variables might be of the wrong types! Type error might still enter your system at the “untyped” boundaries … i.e. when getting json from the network or from local storage or even from the DOM.
By design TypeScript does no type checks at runtime. If you want type checks at runtime you have to implement them. Typically this means some duplication between the types you implement for compile-time checking and the types you build for run-time checking. Libraries like prop-types or io-ts help with defining type-checks at runtime. But there will be some duplication.
Takže nie, stále čítam to, čo som zistil aj sám.
With TypeScript, I can trust my code at runtime
TypeScript is a static type-checking tool, it does not guarantee that your code will run as expected at runtime. Although your function is “typed”, TypeScript ignores the type validation if a developer choose to type-cast the argument to any .
For more information about type-casting, please follow me for Chapter 2.
Remember that TypeScript will not make type assertions at runtime
Hm. Ani TS, ani Java nepomôže. Či dynamicky, či staticky typovaný jazyk, v klient-server aplikácii si vstupy musíte kontrolovať ručne a neveriť jedinej hodnote s pôvodom zo siete.
TypeScript looks more like C#, I don’t need to understand JavaScript
As a JavaScript lover for a long time, I always privilege functional approach compared to Object Oriented one.
I consider that TypeScript should be here to facilitate team work, increase velocity and improve project maintainability.
TypeScript shouldn't be used (in my opinion) to put some non-JavaScript developers on the front-end as fast as possible.
TypeScript is still JavaScript, so understanding JavaScript is important.
To je pre tú lopatu čo mi tu argumentovala, že ani len nemusím vedieť JS a môžem sa rovno naučiť TS.
JavaScript is extremely popular. By using TypeScript, you are focusing on a language that is less popular, therefore the pool of developers that can or want to work on your projects is smaller.
Depending on your project this might be a limitation or a factor that helps to ensure the right developers get on the project.
By choosing TypeScript, you are limiting the pool of developers that might work on your project.
Potvrdenie opodstatnenia mojej otázky, ktoré som tu tiež spomenul.
I worry about building up a large codebase using TypeScript, only to have the ECMAScript spec introduce conflicting keywords and type features
- Eric Elliot, The Shocking Secret About Static Types
TypeScript does not have the same momentum as JavaScript. By using TypeScript you choose a path that bears some more risks than betting on JavaScript.
Also TypeScript does not shield you from having to deeply understand JavaScript. A TypeScript expert must also be a JavaScript expert!
A stále dokola to isté, od iného autora.
Zhrnutie? Nie je to také jednoznačné, tým pádom ani nie jednoduché rozhodnúť sa. Chápem prínos TS, ale možný lock-in, problémy a predraženie ktoré prináša, musí mať silné opodstatnenie. A to vidím asi v takmer každom väčšom projekte, ale stále tu vidím aj veľa use cases, kedy po TS predsalen nesiahnuť.