Its my unpopular opinion that typescript is a flopped product when the full power of ES6 is already available to you. More than 95% browsers of the world already support ES6 and besides, ES6/JavaScript is a standard unlike TS which is a Microsoft product.
Only one high-profile project uses TS and that is Angular2 and there is also a whole lot of mystery about why Google adopted TS in Angular2 despite it being a competitor's product.
Finally, maybe I'm prejudiced because I'm coming from Python/PHP background but I don't like static typing very much. It restricts you in expressiveness especially when it comes to creating complex structures like classes and and interfaces. In fact, a dynamic language like python has no need for interfaces or even classes, modules themselves have the flexibility and modularity to help you build whatever you want.
About TS vs ES6. The debate is totally closed when even Babel 7 enhanced the babel compiler to transform typescript annotation to AST
About what you this is flexibility and modularity, I have one simple example where PHP & Python fail with dynamic typing
Tomorrow you change the type of the return value of a function which is used like a dozen times across all your project. Typescript fails a built time, if you do not update the use of this function. PHP & Python will fail at runtime, sometimes where you didn't thought about (thanks to alias/renaming etc)
With TypeScript itβs possible to write code such that you donβt have to write tests at all to validate certain scenarios. Iβll be writing about that in a future article.
Well, I was talking in general about dynamic typed languages. However, even if we consider that all languages have an X technology like typescript. Why would someone decides that all current and future devs should know about that X technology to avoid such scenarios. While they can simply use universal knowledge such as unit testing or acceptance testing, with minimum learning curve, to ensure a functional app.
Anyway, even if you use typescript there's no escape from testing.
Personally, I don't consider the fact that regression is catchable at compile time as a game changer.
TypeScript will and should not prevent you from writing tests, and it never came to my mind to think about it like that. Also, comparing ES6 vs. TypeScript is misleading. ES6 is simply a new syntax for JavaScript. Since TypeScript is a superset of JavaScript, so of course it is also for ES6.
But let's break down testing. Assuming you have written your test and only considering type errors, it might look like that (though you might automate some steps):
You implement a new feature or are changing an existing one.
You go to your terminal
Start the test
The test runs
Some test indicates failures
You check the failing part of your code
With TypeScript:
You implement a new feature or are changing an existing one and type errors are indicated right away while you are writing
The point is, TypeScript prevents you from making obvious mistakes very early on. Additionally, and I found this to be very useful, you are reminded if variables can be undefined or null. Even if you write tests, you might very well forget to test certain cases. But again, TypeScript should not free you from thinking about all cases that can happen, but it could serve as an additional layer of testing.
Indeed, it's super powerful to have something like realtime testing for your code. However, I still think it's a matter of preferences not a must have technology. I don't like the idea of centralized ecosystem around Microsoft products ( I'm not Microsoft hater tho ). I want to use my editor of choice that not necessarily supports typescript realtime checks. I run tests only once at the end to ensure no regression is happened and my logic is right ( which means my types are right too ).
During writing code HMR and linters are supper enough in my opinion.
Yes, testing is great. But when I converted my old JS code to TS code, I was able to delete 500 lines of test code that was just checking if functions were passing the correct type. I donβt have to check that anymore because TypeScript checks it for me. Bye bye jest.expect().toHaveBeenCalledWith(expect.any<string>, expect.any<number>)
linters are supper enough in my opinion
TypeScript is a linter. In fact itβs tsc runner uses the same AST parsing that EsLint uses.
I donβt like the idea of a centralized ecosystem around Microsoft products (Iβm not Microsoft hater tho)
If youβre not a Microsoft hater, then why mention it at all? Microsoft has really doubled down on open source technology with TypeScript, VSCode, and .NET Core (which typically runs on Linux which is amazing for a company that used to revolve around their operating system sales).
You got rid of 500 lines of test but you sacrificed flexibility. What if a new JavaScript developer ( who is not familiar with typescript ) joins your team? or your company should be exclusive for typescript developers?
Keeping JS or migrating to TS it's a decision that has pros and cons on both situations. It's up to you or to your company to decide what suits you the best and what to sacrifice.
TypeScript is a linter.
Typically, a linter does not enforce you to use a specific syntax neither the ability to transpile. TypeScript is a superset so technically it's a programming language itself.
If youβre not a Microsoft hater, then why mention it at all?
I mentioned it just to make it clear that my opinion is not biased by hatred toward Microsoft still you confused me with a Microsoft's hater.
Personally, I'm very comfortable with many of Microsoft products, I'm writing this from Win10 and I use VSCode occasionally but this does not mean I'll automatically praise any product Microsoft launch.
Though, I'm super happy with the recent contributions Microsoft has made for the open-source community.
What if a new JavaScript developer ( who is not familiar with typescript ) joins your team?
I would be really excited to pair-program with them until they feel comfortable with TypeScript. I'd be really excited to mentor them and to show the value of clearly communicating yourself in code. It's one of the reasons why I'm so passionate about this series I'm writing on TypeScript's emotional/conversational value: dev.to/cubiclebuddha/communicating...
or your company should be exclusive for typescript developers?
I would never dictate the technology for an entire company. The best companies are polyglot and supportive of each team's needs. Now as far as the teams that I lead, I make sure that my teams can develop new features very quickly without having to spend a lot of time fixing old bugs that crop up. So my team members have really gotten used to TypeScript and some have learned to love it.
This is the issue that made me enter the conversation in the first place. Why would you decide that they should use TypeScript. It's okay if that's what your team is comfortable with but this will narrow down your options in term of hiring new talented JavaScript developers ( who are not necessarily interested in TypeScript ).
I would never dictate the technology for an entire company.
Of course, I meant is it okay for your company to use both JavaScript and TypeScript for its projects ?
I meant flexibility in term of expanding the team or sharing the code as not all JS developers required to know TS.
Despite that, I'm really interested to know more about TS and what flexibility it gave you ?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Its my unpopular opinion that
typescript
is a flopped product when the full power of ES6 is already available to you. More than 95% browsers of the world already support ES6 and besides, ES6/JavaScript is a standard unlike TS which is a Microsoft product.Only one high-profile project uses TS and that is Angular2 and there is also a whole lot of mystery about why Google adopted TS in Angular2 despite it being a competitor's product.
Finally, maybe I'm prejudiced because I'm coming from Python/PHP background but I don't like static typing very much. It restricts you in expressiveness especially when it comes to creating complex structures like classes and and interfaces. In fact, a dynamic language like python has no need for interfaces or even classes, modules themselves have the flexibility and modularity to help you build whatever you want.
About TS vs ES6. The debate is totally closed when even Babel 7 enhanced the babel compiler to transform typescript annotation to AST
About what you this is flexibility and modularity, I have one simple example where PHP & Python fail with dynamic typing
(Hope I have been clear)
Only true when you don't have a testing suite. Which is obvious to have when you are doing some serious work.
With TypeScript itβs possible to write code such that you donβt have to write tests at all to validate certain scenarios. Iβll be writing about that in a future article.
Well, I was talking in general about dynamic typed languages. However, even if we consider that all languages have an X technology like typescript. Why would someone decides that all current and future devs should know about that X technology to avoid such scenarios. While they can simply use universal knowledge such as unit testing or acceptance testing, with minimum learning curve, to ensure a functional app.
Anyway, even if you use typescript there's no escape from testing.
Personally, I don't consider the fact that regression is catchable at compile time as a game changer.
TypeScript will and should not prevent you from writing tests, and it never came to my mind to think about it like that. Also, comparing ES6 vs. TypeScript is misleading. ES6 is simply a new syntax for JavaScript. Since TypeScript is a superset of JavaScript, so of course it is also for ES6.
But let's break down testing. Assuming you have written your test and only considering type errors, it might look like that (though you might automate some steps):
With TypeScript:
The point is, TypeScript prevents you from making obvious mistakes very early on. Additionally, and I found this to be very useful, you are reminded if variables can be undefined or null. Even if you write tests, you might very well forget to test certain cases. But again, TypeScript should not free you from thinking about all cases that can happen, but it could serve as an additional layer of testing.
Indeed, it's super powerful to have something like realtime testing for your code. However, I still think it's a matter of preferences not a must have technology. I don't like the idea of centralized ecosystem around Microsoft products ( I'm not Microsoft hater tho ). I want to use my editor of choice that not necessarily supports typescript realtime checks. I run tests only once at the end to ensure no regression is happened and my logic is right ( which means my types are right too ).
During writing code HMR and linters are supper enough in my opinion.
Yes, testing is great. But when I converted my old JS code to TS code, I was able to delete 500 lines of test code that was just checking if functions were passing the correct type. I donβt have to check that anymore because TypeScript checks it for me. Bye bye
jest.expect().toHaveBeenCalledWith(expect.any<string>, expect.any<number>)
TypeScript is a linter. In fact itβs tsc runner uses the same AST parsing that EsLint uses.
If youβre not a Microsoft hater, then why mention it at all? Microsoft has really doubled down on open source technology with TypeScript, VSCode, and .NET Core (which typically runs on Linux which is amazing for a company that used to revolve around their operating system sales).
You got rid of 500 lines of test but you sacrificed flexibility. What if a new JavaScript developer ( who is not familiar with typescript ) joins your team? or your company should be exclusive for typescript developers?
Keeping JS or migrating to TS it's a decision that has pros and cons on both situations. It's up to you or to your company to decide what suits you the best and what to sacrifice.
Typically, a linter does not enforce you to use a specific syntax neither the ability to transpile. TypeScript is a superset so technically it's a programming language itself.
I mentioned it just to make it clear that my opinion is not biased by hatred toward Microsoft still you confused me with a Microsoft's hater.
Personally, I'm very comfortable with many of Microsoft products, I'm writing this from Win10 and I use VSCode occasionally but this does not mean I'll automatically praise any product Microsoft launch.
Though, I'm super happy with the recent contributions Microsoft has made for the open-source community.
I would be really excited to pair-program with them until they feel comfortable with TypeScript. I'd be really excited to mentor them and to show the value of clearly communicating yourself in code. It's one of the reasons why I'm so passionate about this series I'm writing on TypeScript's emotional/conversational value: dev.to/cubiclebuddha/communicating...
I would never dictate the technology for an entire company. The best companies are polyglot and supportive of each team's needs. Now as far as the teams that I lead, I make sure that my teams can develop new features very quickly without having to spend a lot of time fixing old bugs that crop up. So my team members have really gotten used to TypeScript and some have learned to love it.
This is the issue that made me enter the conversation in the first place. Why would you decide that they should use TypeScript. It's okay if that's what your team is comfortable with but this will narrow down your options in term of hiring new talented JavaScript developers ( who are not necessarily interested in TypeScript ).
Of course, I meant is it okay for your company to use both JavaScript and TypeScript for its projects ?
Yes, a company should be free to have teams that use whatever language that makes them the most productive.
I really can't see how using TS sacrifice flexibility... On the contrary I've gained a lot more...
I meant flexibility in term of expanding the team or sharing the code as not all JS developers required to know TS.
Despite that, I'm really interested to know more about TS and what flexibility it gave you ?