{"id":9967,"date":"2021-05-21T10:00:50","date_gmt":"2021-05-21T01:00:50","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=9967"},"modified":"2021-05-20T19:58:10","modified_gmt":"2021-05-20T10:58:10","slug":"typescript","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/9967","title":{"rendered":"TypeScript"},"content":{"rendered":"\n<p>TypeScript stands in an unusual relationship to JavaScript. TypeScript offers all of JavaScript\u2019s features, and an additional layer on top of these: TypeScript\u2019s type system.<\/p>\n\n\n\n<p>TypeScript is a modern age JavaScript development language.<\/p>\n\n\n\n<p>There are a lot of benefits of adding static typing to JavaScript. You\u2019ll not see that&nbsp;undefined&nbsp;pop up in your applications anymore. Refactoring code will not be a nightmare anymore. And many more. A study shows that 15% of JavaScript bugs can be detected by TypeScript.<\/p>\n\n\n\n<h4>Types \u2014 The difference between JS and TS<\/h4>\n\n\n\n<p>Programming languages fall into two categories: statically typed or dynamically typed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Function getWidth(width){\n\u3000return num + 3\n}<\/code><\/pre>\n\n\n\n<p>Here, the type of variable width is not known. If I call this with, getWidth(\u201cI love TS\u201d) it will print I love TS3. This is known as type coercion. If it can, Javascript will see that it is trying to add a string and a number together, and it will convert the number to its string equivalent and concatenate them.<\/p>\n\n\n\n<p>With TypeScript, I could do the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function getWidth(width: number) {\n    return num + \uff13\n}<\/code><\/pre>\n\n\n\n<p>We just added the type of variable width as a <code>number<\/code>. If I call&nbsp;<code>add(\u201cI love TS\u201d)<\/code>&nbsp;now, it\u2019ll throw a compilation error \u2014&nbsp;<strong>Argument of type&nbsp;<\/strong><code><strong>string<\/strong><\/code><strong>&nbsp;is not assignable to parameter of type&nbsp;<\/strong><code><strong>number<\/strong><\/code>&nbsp;.<\/p>\n\n\n\n<p>Catching the error instantly allows me to save time and check why my input is not the type I think it is, rather than having to trace my steps back much later in the process without being sure where the error is occurring.<\/p>\n\n\n\n<p>Benefits of Static Typing<\/p>\n\n\n\n<ul><li>TypeScript is that it offers the ability to add static types to your JavaScript code. <\/li><li>Static typing allows you to catch errors earlier in the debugging process.<\/li><li>Adding strict types makes code more readable. A code that speaks for itself can offset the lack of direct communication between team members.<\/li><\/ul>\n\n\n\n<p>By Ami<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9967\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/9967\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"TypeScript\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9967\" data-text=\"TypeScript\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9967\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9967\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>TypeScript stands in an unusual relationship to JavaScript. TypeScript offers all of JavaScript\u2019s features, an [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9967"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=9967"}],"version-history":[{"count":11,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9967\/revisions"}],"predecessor-version":[{"id":9980,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9967\/revisions\/9980"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=9967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=9967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=9967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}