{"id":1191,"date":"2016-07-08T14:43:18","date_gmt":"2016-07-08T14:43:18","guid":{"rendered":"https:\/\/ionic.io\/blog\/?p=1191"},"modified":"2016-07-08T22:03:29","modified_gmt":"2016-07-08T22:03:29","slug":"ionic-and-typings","status":"publish","type":"post","link":"https:\/\/ionic.io\/blog\/ionic-and-typings","title":{"rendered":"Ionic and Typings"},"content":{"rendered":"<p>Picture this, if you will&#8230;<\/p>\n<p>You just found this new JavaScript library, and you want to use it in your slick new Ionic 2 app. You <code>npm install<\/code> the library, go to import it, and then&#8230;nothing. <em>Nothing happens<\/em>. What gives?<\/p>\n<p>Turns out, mixing JavaScript and TypeScript can be problematic when TypeScript doesn&#8217;t understand the extra code. In this screencast, we&#8217;ll go over the steps needed to make TypeScript play nice with other JavaScript libraries.<br \/>\n<!--more--><\/p>\n<div class=\"video-container\">\n              <iframe data-src=\"https:\/\/www.youtube.com\/embed\/m3tEWHP8WWo\"frameborder=\"0\" allowfullscreen src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n            <\/div>\n<pre><code class=\"bash\">npm install -g typings\ntypings search lodash\ntypings install lodash --save\n<\/code><\/pre>\n<h3>Typings<\/h3>\n<p>Let&#8217;s look at Typings a bit more and check out some of the details. Typings is a successor to a few other tools out there for managing type definitions. These are files that describe a bit of code, so the compile can provide feedback if you pass it an incorrect type. These type definitions can have many sources.<\/p>\n<ul>\n<li><code>npm<\/code> &#8211; dependencies from <a href=\"http:\/\/npmjs.org\/\">NPM<\/a><\/li>\n<li><code>github<\/code> &#8211; dependencies directly from <a href=\"https:\/\/github.com\/\">GitHub<\/a> (E.g. <a href=\"http:\/\/duojs.org\/\">Duo<\/a>, <a href=\"http:\/\/jspm.io\/\">JSPM<\/a>)<\/li>\n<li><code>bower<\/code> &#8211; dependencies from <a href=\"http:\/\/bower.io\/\">Bower<\/a><\/li>\n<li><code>common<\/code> &#8211; &#8220;standard&#8221; libraries without a known &#8220;source&#8221;<\/li>\n<li><code>shared<\/code> &#8211; shared library functionality<\/li>\n<li><code>lib<\/code> &#8211; shared environment functionality (mirror of <code>shared<\/code>) (<code>--global<\/code>)<\/li>\n<li><code>env<\/code> &#8211; environments (E.g. <code>atom<\/code>, <code>electron<\/code>) (<code>--global<\/code>)<\/li>\n<li><code>global<\/code> &#8211; global (<code>window.&lt;var&gt;<\/code>) libraries (<code>--global<\/code>)<\/li>\n<li><code>dt<\/code> &#8211; typings from <a href=\"https:\/\/github.com\/DefinitelyTyped\/DefinitelyTyped\">DefinitelyTyped<\/a> (usually <code>--global<\/code>)<\/var><\/li>\n<\/ul>\n<p><em>Taken from Typings README<\/em><\/p>\n<p>This can seem like a lot, but it&#8217;s fairly easy to reason about when you look at some of the most common sources.<\/p>\n<ul>\n<li><code>npm<\/code> &#8211; Definitions for modules that are from NPM<\/li>\n<li><code>dt<\/code> &#8211; Definitions from the legacy repo, Definitely Typed<\/li>\n<\/ul>\n<p>For the most part, these are the main places from which you&#8217;ll see Typings pull. If you admit a warning, and Typings cannot resolve it, it will prompt you with a warning, letting you know where you can install the definitions from.<\/p>\n<p>A common issue that people can face is handling global definitions. For example, let&#8217;s try to install the ES6-shim definitions from typings.<\/p>\n<pre><code class=\"bash\">typings install dt~es6-shim\ntypings ERR! message Attempted to compile &quot;es6-shim&quot; as an external module, but it looks like a global module. You&#039;ll need to enable the global option to continue.\n\ntypings ERR! cwd \/Users\/mhartington\/GitHub\/ionic\/tmp\ntypings ERR! system Darwin 16.0.0\ntypings ERR! command &quot;\/usr\/local\/Cellar\/node\/6.3.0\/bin\/node&quot; &quot;\/usr\/local\/bin\/typings&quot; &quot;install&quot; &quot;dt~es6-shim&quot;\ntypings ERR! node -v v6.3.0\ntypings ERR! typings -v 1.3.1\n\ntypings ERR! If you need help, you may report this error at:\ntypings ERR! &amp;lt;https:\/\/github.com\/typings\/typings\/issues&amp;gt;\n<\/code><\/pre>\n<p>This error looks bad, but it&#8217;s actually extremely helpful. The ES6-shim module is a global module, meaning it sits on the <code>window<\/code> object of the browser. So we need to tell the TypeScript compiler that this is global module, and we <em>know<\/em> it will be available at runtime.<\/p>\n<h3>Closing words<\/h3>\n<p>While at first it can feel very frustrating to get everything to work together, with a little setup, TypesScript projects and JavaScript libraries can work together perfectly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Picture this, if you will&#8230; You just found this new JavaScript library, and you want to use it in your slick new Ionic 2 app. You npm install the library, go to import it, and then&#8230;nothing. Nothing happens. What gives? Turns out, mixing JavaScript and TypeScript can be problematic when TypeScript doesn&#8217;t understand the extra [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"publish_to_discourse":"","publish_post_category":"","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"","discourse_permalink":"","wpdc_publishing_response":"","wpdc_publishing_error":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[13],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-all","tag-ionic-2"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.0 (Yoast SEO v23.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ionic and Typings - Ionic Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ionic.io\/blog\/ionic-and-typings\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ionic and Typings\" \/>\n<meta property=\"og:description\" content=\"Picture this, if you will&#8230; You just found this new JavaScript library, and you want to use it in your slick new Ionic 2 app. You npm install the library, go to import it, and then&#8230;nothing. Nothing happens. What gives? Turns out, mixing JavaScript and TypeScript can be problematic when TypeScript doesn&#8217;t understand the extra [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ionic.io\/blog\/ionic-and-typings\" \/>\n<meta property=\"og:site_name\" content=\"Ionic Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-08T14:43:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-08T22:03:29+00:00\" \/>\n<meta name=\"author\" content=\"Mike Hartington\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mhartington\" \/>\n<meta name=\"twitter:site\" content=\"@ionicframework\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Hartington\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings#article\",\"isPartOf\":{\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings\"},\"author\":{\"name\":\"Mike Hartington\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/c8c92b04d526adb925ea514c619a267b\"},\"headline\":\"Ionic and Typings\",\"datePublished\":\"2016-07-08T14:43:18+00:00\",\"dateModified\":\"2016-07-08T22:03:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings\"},\"wordCount\":382,\"commentCount\":20,\"publisher\":{\"@id\":\"https:\/\/ionic.io\/blog\/#organization\"},\"keywords\":[\"Ionic 2\"],\"articleSection\":[\"All\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ionic.io\/blog\/ionic-and-typings#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings\",\"url\":\"https:\/\/ionic.io\/blog\/ionic-and-typings\",\"name\":\"Ionic and Typings - Ionic Blog\",\"isPartOf\":{\"@id\":\"https:\/\/ionic.io\/blog\/#website\"},\"datePublished\":\"2016-07-08T14:43:18+00:00\",\"dateModified\":\"2016-07-08T22:03:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ionic.io\/blog\/ionic-and-typings\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ionic.io\/blog\/ionic-and-typings#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ionic.io\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ionic and Typings\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ionic.io\/blog\/#website\",\"url\":\"https:\/\/ionic.io\/blog\/\",\"name\":\"ionic.io\/blog\",\"description\":\"Build amazing native and progressive web apps with the web\",\"publisher\":{\"@id\":\"https:\/\/ionic.io\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ionic.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/ionic.io\/blog\/#organization\",\"name\":\"Ionic\",\"url\":\"https:\/\/ionic.io\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png\",\"contentUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png\",\"width\":1920,\"height\":854,\"caption\":\"Ionic\"},\"image\":{\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/ionicframework\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/c8c92b04d526adb925ea514c619a267b\",\"name\":\"Mike Hartington\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2018\/08\/mike-headshot-2-smaller-150x150.png\",\"contentUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2018\/08\/mike-headshot-2-smaller-150x150.png\",\"caption\":\"Mike Hartington\"},\"description\":\"Director of Developer Relations\",\"sameAs\":[\"https:\/\/twitter.com\/mhartington\",\"https:\/\/x.com\/mhartington\"],\"url\":\"https:\/\/ionic.io\/blog\/author\/mike\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ionic and Typings - Ionic Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ionic.io\/blog\/ionic-and-typings","og_locale":"en_US","og_type":"article","og_title":"Ionic and Typings","og_description":"Picture this, if you will&#8230; You just found this new JavaScript library, and you want to use it in your slick new Ionic 2 app. You npm install the library, go to import it, and then&#8230;nothing. Nothing happens. What gives? Turns out, mixing JavaScript and TypeScript can be problematic when TypeScript doesn&#8217;t understand the extra [&hellip;]","og_url":"https:\/\/ionic.io\/blog\/ionic-and-typings","og_site_name":"Ionic Blog","article_published_time":"2016-07-08T14:43:18+00:00","article_modified_time":"2016-07-08T22:03:29+00:00","author":"Mike Hartington","twitter_card":"summary_large_image","twitter_creator":"@mhartington","twitter_site":"@ionicframework","twitter_misc":{"Written by":"Mike Hartington","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ionic.io\/blog\/ionic-and-typings#article","isPartOf":{"@id":"https:\/\/ionic.io\/blog\/ionic-and-typings"},"author":{"name":"Mike Hartington","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/c8c92b04d526adb925ea514c619a267b"},"headline":"Ionic and Typings","datePublished":"2016-07-08T14:43:18+00:00","dateModified":"2016-07-08T22:03:29+00:00","mainEntityOfPage":{"@id":"https:\/\/ionic.io\/blog\/ionic-and-typings"},"wordCount":382,"commentCount":20,"publisher":{"@id":"https:\/\/ionic.io\/blog\/#organization"},"keywords":["Ionic 2"],"articleSection":["All"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ionic.io\/blog\/ionic-and-typings#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ionic.io\/blog\/ionic-and-typings","url":"https:\/\/ionic.io\/blog\/ionic-and-typings","name":"Ionic and Typings - Ionic Blog","isPartOf":{"@id":"https:\/\/ionic.io\/blog\/#website"},"datePublished":"2016-07-08T14:43:18+00:00","dateModified":"2016-07-08T22:03:29+00:00","breadcrumb":{"@id":"https:\/\/ionic.io\/blog\/ionic-and-typings#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ionic.io\/blog\/ionic-and-typings"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ionic.io\/blog\/ionic-and-typings#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ionic.io\/blog"},{"@type":"ListItem","position":2,"name":"Ionic and Typings"}]},{"@type":"WebSite","@id":"https:\/\/ionic.io\/blog\/#website","url":"https:\/\/ionic.io\/blog\/","name":"ionic.io\/blog","description":"Build amazing native and progressive web apps with the web","publisher":{"@id":"https:\/\/ionic.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ionic.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ionic.io\/blog\/#organization","name":"Ionic","url":"https:\/\/ionic.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png","contentUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png","width":1920,"height":854,"caption":"Ionic"},"image":{"@id":"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/ionicframework"]},{"@type":"Person","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/c8c92b04d526adb925ea514c619a267b","name":"Mike Hartington","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2018\/08\/mike-headshot-2-smaller-150x150.png","contentUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2018\/08\/mike-headshot-2-smaller-150x150.png","caption":"Mike Hartington"},"description":"Director of Developer Relations","sameAs":["https:\/\/twitter.com\/mhartington","https:\/\/x.com\/mhartington"],"url":"https:\/\/ionic.io\/blog\/author\/mike"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":0,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"wp:attachment":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}