<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: brieucp</title>
    <description>The latest articles on DEV Community by brieucp (@brieucp).</description>
    <link>https://dev.to/brieucp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F197493%2F1cc2e20b-d12e-45fd-81ed-2bef12cb7054.png</url>
      <title>DEV Community: brieucp</title>
      <link>https://dev.to/brieucp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brieucp"/>
    <language>en</language>
    <item>
      <title>Why so much hype over Typescript ?</title>
      <dc:creator>brieucp</dc:creator>
      <pubDate>Tue, 24 Sep 2019 14:28:51 +0000</pubDate>
      <link>https://dev.to/brieucp/why-so-much-hype-over-typescript-4p80</link>
      <guid>https://dev.to/brieucp/why-so-much-hype-over-typescript-4p80</guid>
      <description>&lt;h2&gt;
  
  
  Some context
&lt;/h2&gt;

&lt;p&gt;First of all, don't misunderstand me, &lt;strong&gt;TYPES ARE GREAT&lt;/strong&gt;. I use Typescript everyday at work and the goal of this post isn't to question the benefits of a type system. Because types give context, save us from stupid mistake and allow us to avoid performance issues by avoiding most of the automatic type inference performed by js interpreter during JIT compilation and run-time. I think that anybody should use a typing system while building javascript if he ever think to share it or to maintain it in the long run. &lt;/p&gt;

&lt;p&gt;But as much as I appreciate the benefits of Typescript as a type system (even if several of my coworkers use so much &lt;strong&gt;any&lt;/strong&gt; that in most places of the app it doesn't bring any benefit at all compare to pure javascript). I'm skeptical about Typescript as a compiler. All the following argument and reflexion concern Typescript as a compiler and a superset of javascript instead of a type system enhancing javascript. &lt;/p&gt;

&lt;h2&gt;
  
  
  It add a lot of complexity for minimal benefit
&lt;/h2&gt;

&lt;p&gt;While using typescript you need to configure it and it's not simple. The options are not clear at all and documentation is obscure. As an example, ask yourself what are the differences between &lt;em&gt;target&lt;/em&gt; and &lt;em&gt;module&lt;/em&gt; options.&lt;br&gt;
Ok, so target is straightforward &lt;em&gt;spoil: not really&lt;/em&gt; it's your target environment...&lt;br&gt;
But wait ?!? What exactly is ES2017 ? And ES2018 ?&lt;br&gt;
Let's take a look at ES2017 as an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://caniuse.com/#search=Object.values"&gt;Object.values&lt;/a&gt;/&lt;a href="https://caniuse.com/#search=Object.entries"&gt;Object.entries&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://caniuse.com/#search=String.prototype.padStart"&gt;String padding&lt;/a&gt;; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://caniuse.com/#search=getOwnPropertyDescriptors"&gt;Object.getOwnPropertyDescriptors&lt;/a&gt;; &lt;/li&gt;
&lt;li&gt;Trailing commas in function parameter lists and calls; &lt;/li&gt;
&lt;li&gt;And &lt;a href="https://caniuse.com/#search=Async%20functions"&gt;Async functions&lt;/a&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, Great. But which navigator are supporting this exact set of features ? Other question, did you knew that ES2017 was this set of feature without checking the can i use link ? I didn't.&lt;/p&gt;

&lt;p&gt;So using the target options you have to know which version of ECMAscript the feature you want is from. Then you have to check if your target browser support this feature or (if the feature is polyfillable) write the code anyway and deal with the bloated code. If you check the can i use link you should also have noticed that even if all this list of features are part of ES2017. It doesn't mean anything for the browser version. Because web browser implement ecmascript features independently. If you were using Babel you could use @babel/preset-env and using &lt;a href="https://github.com/browserslist/browserslist"&gt;browserslist&lt;/a&gt; target exactly the browser you want with &lt;strong&gt;meaningfull&lt;/strong&gt; query (Nota: you should still be carreful &lt;a href="https://medium.com/@WebReflection/avoiding-babels-production-bloat-d53eea2e1cbf"&gt;about production bloat&lt;/a&gt; but you can be more serine knowing that at least the code you're shipping to the user is useful)&lt;/p&gt;

&lt;p&gt;There is also the fact that the compiler options include options about minification. Which could be explain by the fact that typescript goal is to handle completely the bundling process. But it's not the case. In most case you still need to add a real module bundler to you build chain to be able to make something real with typescript.&lt;/p&gt;

&lt;p&gt;Finally there is the fact that the typecript compiler have some constraint. For example if you want to use dynamic import you must use &lt;em&gt;module: "esnext"&lt;/em&gt; which you can't if targeting ES2015 even if you bundler (webpack or parcel) support it. Which means you can't split your code while targeting legacy browser...&lt;/p&gt;

&lt;h2&gt;
  
  
  Typescript isn't really a superset of javascript anymore
&lt;/h2&gt;

&lt;p&gt;There are some differences between pure javascript and typescript. For example between @decorators in typescript and what is currently being normalized in ECMAScript. Which will probably lead to some difference at run-time when using them once they are implemented natively by browser. &lt;/p&gt;

&lt;p&gt;In addition of that it is possible to write &lt;strong&gt;today&lt;/strong&gt; &lt;a href="https://medium.com/@jasvir/monoglots-when-a-subset-is-not-1604e3a51d9"&gt;valid code which would be parsed differently by the typescript and the javascript&lt;/a&gt; parser which will lead to different run-time execution. I know, I know, it's really unlikely that you ever encounter any usecase like this one. But it doesn't stop the reality of this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use JSDoc instead
&lt;/h2&gt;

&lt;p&gt;As I said before, I still think we should type our code. In fact it's really easy to do it even without typescript. &lt;a href="https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html"&gt;We just have to write JSDoc declaration in plain javascript file&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We can then use typescript to type check them with the --CheckJs option.&lt;br&gt;
You can also set VS Code (and probably most of the text editor and IDE in the wild) to show type checking on JS file by enabling Check JS in the parameters. &lt;/p&gt;

&lt;p&gt;A big advantage to use JSDoc instead of typescript is that you write javascript which remove any need for a compilation step. You can still use babel if you want but you can also be happy with Javascript.&lt;/p&gt;

&lt;p&gt;Some ressource about JSDoc:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/@trukrs/type-safe-javascript-with-jsdoc-7a2a63209b76"&gt;Type Safe JavaScript with JSDoc&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jsdoc.app/"&gt;JSDoc.app&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Now, I'm not asking you to ditch typescript. If you're happy with it, stick with it. I'm just wondering why everyone jumped in the typescript train when for the most part I see more constraint than benefit compared to a some regular types included in comments. &lt;/p&gt;




&lt;p&gt;PS: I didn't talk about tslint vs eslint &lt;a href="https://eslint.org/blog/2019/01/future-typescript-eslint"&gt;because everyone agree on the superiority of typescript&lt;/a&gt;. Since I talked about browserify, I must also talk about one of my favorite plugin for eslint which is &lt;a href="https://github.com/amilajack/eslint-plugin-compat"&gt;eslint-plugin-compat&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PPS: English is not my native language so don't hesitate to correct anything. I used a corrector but its probably not perfect.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
