{"id":13503,"date":"2016-06-28T16:15:03","date_gmt":"2016-06-28T13:15:03","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=13503"},"modified":"2018-01-10T16:32:55","modified_gmt":"2018-01-10T14:32:55","slug":"typescript-example-using-requirejs","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/","title":{"rendered":"TypeScript example using RequireJS"},"content":{"rendered":"<h2><a name=\"intro\"><\/a>1. TypeScript with RequireJS<\/h2>\n<p>In this article we are going to explain how to create a TypeScript application and separate its components in modules. After that we are going to show how to load these modules using AMD with RequireJS and the TypeScript compiler options to support it.<br \/>\nAll code and examples used in this tutorial are available in the download section at the end of this article.<br \/>\nBefore starting with the article you need to install NodeJS in your system. Instructions can be found here: <a href=\"https:\/\/nodejs.org\/en\/\">https:\/\/nodejs.org\/en\/<\/a>.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#intro\">1. TypeScript with RequireJS<\/a><\/dt>\n<dt><a href=\"#requirejs\">2. RequireJS<\/a><\/dt>\n<dt><a href=\"#typescript\">3. TypeScript<\/a><\/dt>\n<dt><a href=\"#create\">4. Creating a TypeScript project with NodeJS<\/a><\/dt>\n<dt><a href=\"#modules\">5. Modules in TypeScript<\/a><\/dt>\n<dt><a href=\"#example\">6. Example<\/a><\/dt>\n<dt><a href=\"#options\">7. Options<\/a><\/dt>\n<dt><a href=\"#download\">8. Download<\/a><\/dt>\n<dt><a href=\"#links\">9. Links<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"requirejs\"><\/a>2. RequireJS<\/h2>\n<p>RequireJS is an AMD JavaScript library that supports asynchronous file and module loading. It is optimized for web browser usage but it is also possible to use in Java or Node environments. It is compatible with all main browsers and quite intuitive to use. Its main benefit is that it offers the option to logically structure an application following the AMD principles.<\/p>\n<p>In the article <a href=\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/requirejs-tutorial-how-to-use-requirejs\/\">https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/requirejs-tutorial-how-to-use-requirejs\/<\/a> you can find more information about how to use RequireJS.<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;tCIwOngQUb3zSUuF&#8217;]<\/p>\n<h2><a name=\"typescript\"><\/a>3. TypeScript<\/h2>\n<p>TypeScript is a free and open source programming language created and supported by Microsoft. It enhances basic JavaScript with Object Oriented capabilities like object typing and classes support. Applications writen in TypeScript need to be transcompiled to JavaScript. The compiler is called <code>tsc<\/code> and code written in TypeScript can be compiled to JavaScript in almost any JavaScript engine like NodeJS or a Browser, in this example we are going to use NodeJS to compile the application.<\/p>\n<p>As we said before we are going to install TypeScript using NodeJS, in order to do that, you can type:<\/p>\n<pre class=\"brush:bash\">npm install -g typescript\r\n\r\n<\/pre>\n<p>To check that the installation has been successfull please type <code>tsc<\/code> in your console and something like the following should appear:<\/p>\n<pre class=\"brush:bash\">Version 1.8.10\r\nSyntax:   tsc [options] [file ...]\r\n\r\nExamples: tsc hello.ts\r\n          tsc --out file.js file.ts\r\n          tsc @args.txt\r\n\r\nOptions:\r\n --allowJs                           Allow javascript files to be compiled.\r\n --allowSyntheticDefaultImports      Allow default imports from modules with no default export. This does not affect code emit, just typechecking.\r\n --allowUnreachableCode              Do not report errors on unreachable code.\r\n --allowUnusedLabels                 Do not report errors on unused labels.\r\n -d, --declaration                   Generates corresponding '.d.ts' file.\r\n...\r\n<\/pre>\n<p>A good explanation and overview about TypeScript can be found in <a href=\"https:\/\/en.wikipedia.org\/wiki\/TypeScript\">https:\/\/en.wikipedia.org\/wiki\/TypeScript<\/a>.<\/p>\n<h2><a name=\"create\"><\/a>4. Creating a TypeScript project with NodeJS<\/h2>\n<p>In order to create our application we type the following<\/p>\n<pre class=\"brush:bash\">npm init \r\n<\/pre>\n<p>and we accept all options that are prompted (in case you want to modify some, fell free to do it).<\/p>\n<p>We edit the package.json file and include the following to indicate a TypeScript dependency:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\n\"dependencies\": {\r\n    \"typescript\": \"^1.8.10\"\r\n  }\r\n<\/pre>\n<p>After that we edit again the package.json and add a new script to run the TypeScript compiler <code>tsc<\/code>:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see complete JSON\r\n \"scripts\": {\r\n    \"test\": \"test\",\r\n    \"tsc_amd\": \"tsc --module amd Game.ts\"\r\n  },\r\n<\/pre>\n<p>We will explain later what options we are passing to the compiler.<\/p>\n<h2><a name=\"modules\"><\/a>5. Modules in TypeScript<\/h2>\n<p>Modules is all about scoping. That is classes, methods, functions, etc. declared in the scope of a module are not visible outside this scope. In order to make them visible they need to be exported. The same applies for using this variable, function, class, method, whatever outside this module: it needs to be imported.<\/p>\n<p>Modules features can be exported in one of the following ways:<\/p>\n<ul>\n<ul>\n<li>using the keyword <code>export<\/code>, like in:<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\nexport const name = \"dani\";\r\n<\/pre>\n<ul>\n<ul>\n<li>using export statements, for example:<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\nclass Saluter{\r\n    hi(s: string) {\r\n        return \"hello \" + name;\r\n    }\r\n}\r\nexport { Saluter};\r\nexport { Saluter as MySaluter };\r\n<\/pre>\n<ul>\n<ul>\n<li>using <code>export =<\/code>, in this case <code>import let = require(\"module\")<\/code> needs to be used. This option will be used in the article. For example:<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\nclass Salute{\r\n    hi(s: name) {\r\n        return \"hello \" + name;\r\n    }\r\n}\r\nexport = Salute;\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\nimport salute = require(\".\/Salute\");\r\nlet saluter= new salute();\r\nconsole.log(saluter.hi(\"Dani\");\r\n<\/pre>\n<p>Imports can be done in one of the following ways:<\/p>\n<ul>\n<ul>\n<li>Import a single export from a module<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\nimport { Salute} from \".\/Salute\";\r\n\r\nlet salute = new Salute();\r\n<\/pre>\n<ul>\n<ul>\n<li>Import the entire module into a single variable, and use it to access the module exports<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>nofile.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see similar JS code\r\n\r\nimport * as saluter from \".\/Salute\";\r\nlet sal = new saluter.Salute();\r\n\r\n<\/pre>\n<p>Once we know how to create modules in TypeScript and how to export and import them and their properties, we need to generate them by indicating the tsc compiler what module target we are going to use. Possible targets are:<\/p>\n<ul>\n<li>CommonJS (for NodeJS apps)<\/li>\n<li>AMD \/ RequireJS<\/li>\n<li>UMD<\/li>\n<li>SystemJS<\/li>\n<li>ECMAScript 2015 native modules<\/li>\n<\/ul>\n<p>The target is indicated to the compiler with the option <code>--module<\/code>, like:<\/p>\n<pre class=\"brush:bash\">tsc --module  \r\n<\/pre>\n<p>In this article we are going to show how to generate modules for AMD RequireJS based applications. This can be done by typing:<\/p>\n<pre class=\"brush:bash\">tsc --module amd \r\n<\/pre>\n<p>In order to generate just one output file the option <code>outFile<\/code> can be used in combination with the <code>--module amd<\/code> shown before.<\/p>\n<p>This is just a brief explanation to support our example. For more information about modules in TypeScript please visit <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/modules.html\">https:\/\/www.typescriptlang.org\/docs\/handbook\/modules.html<\/a>.<\/p>\n<h2><a name=\"example\"><\/a>6. Example<\/h2>\n<p>In this chapter we are going to apply all this theory. We are going to create a TypeScript application divided in different files containing different modules that need to work with each other. Then we are going to launch the application without any module target and we are going to see what happens. Finally we are going to generate the application to run using RequireJS as module target using the compiler options explained before.<\/p>\n<p>Here are some of the classes used in the application (you can download all of them in the download section of this article). Game.ts contains the code needed to play a game between two teams:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Game.ts<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\nimport Team = require(\"Team\");\r\n\r\nclass Game{\r\n    home: Team;\r\n    away: Team;\r\n    date: number;\/\/epoch\r\n    location: string;\r\n\r\n\r\n    constructor(home?:Team, away?:Team, date?: number, location?: string){\r\n        if(home != null){\r\n            this.home = home;\r\n        }else{\r\n            this.home = new Team();\r\n        }\r\n\r\n        if(away != null){\r\n            this.away = away;\r\n        }else{\r\n            this.away = new Team();\r\n        }\r\n\r\n        if(date != null){\r\n            this.date = date;\r\n        }else{\r\n            this.date = 1000;\r\n        }\r\n\r\n        if(location != null){\r\n            this.location = location;\r\n        }else{\r\n            this.location = 'Carlos Tartiere, Oviedo';\r\n        }\r\n    }\r\n\r\n    toString(){\r\n        return this.home.name + \" against \" + this.away.name + \" at \" + this.date + \" in \" + this.location;\r\n    }\r\n}\r\n\r\nexport = Game;\r\n<\/pre>\n<p>Team.ts containing a coach, a director and a bunch of players per team:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Team.ts<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\nimport Coach = require(\"Coach\");\r\nimport Director = require(\"Director\");\r\nimport Player = require(\"Player\");\r\n\r\nclass Team {\r\n\r\n    name: string;\r\n    coach:Coach;\r\n    director:Director;\r\n    players:[Player];\r\n\r\n    generateRandomPlayers() {\r\n        this.players = [new Player(), new Player(), new Player(), new Player(), new Player(), new Player(), new Player(), new Player(), new Player(), new Player(), new Player()];\r\n    }\r\n\r\n    constructor() {\r\n        this.name=\"Real Oviedo\";\r\n        this.coach = new Coach();\r\n        this.director = new Director();\r\n        this.generateRandomPlayers();\r\n    }\r\n\r\n}\r\n\r\nexport = Team;\r\n<\/pre>\n<p>A Player abstraction:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Player.ts<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\nimport Person = require(\"Person\");\r\n\r\nclass Player implements Person {\r\n    firstName: string;\r\n    lastName: string;\r\n    age: number;\r\n    country: string;\r\n    goals: number;\r\n    caps: number;\r\n\r\n    constructor (){\r\n        this.firstName = \"Andres\";\r\n        this.lastName = \"Iniesta\";\r\n        this.age = 31;\r\n        this.country = 'Spain';\r\n        this.goals = 22;\r\n        this.caps = 100;\r\n    }\r\n}\r\n\r\nexport = Player;\r\n<\/pre>\n<p>Here we show a small snippet from the index.html where the require.js file is launched and initialized using the configuration file main.js and the game is initialized and started by requiring its entry point using RequireJS require function and calling its main method. Other files are not shown since they do not add any value to the article, as said, you can download them at the end of this tutorial:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\n\r\n&lt;script src=\"require.js\" data-main=\"main.js\"&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;button class=\"play\" value=\"play\" onclick=\"play();\"&gt;play&lt;\/button&gt;\r\n\r\n&lt;script&gt;\r\n    function play() {\r\n        require(['Game'], function (Game) {\r\n            var game = new Game();\r\n            console.log(game.toString());\r\n        });\r\n    }\r\n\r\n&lt;\/script&gt;\r\n\r\n<\/pre>\n<p>We can generate the application typing:<\/p>\n<pre class=\"bash\">npm run tsc_amd\r\n<\/pre>\n<p>This launches the tsc compiler with the needed options to generate AMD RequireJS compatible JavaScript files, as stated in our package.json file. Now we can launch the index.html in our browser, click the button and check what happens in the console. I recommend to debug the application to check what files are loaded and how the files have been generated.<\/p>\n<p>In combination with <code>--module amd<\/code> you can use <code>--outFile file<\/code> to combine all output in one file, something like:<\/p>\n<pre class=\"brush:bash\">tsc --module amd --outFile GameCompact.js Game.ts\r\n<\/pre>\n<p>So all required content is available in the new file GameCompact.js. The tsc options listed above can be entered in the package json file as a new script. This provides us more flexibility. Here is how the npm configuration package.json file looks like (I repeat, everything can be found in the archived file at the end of the article):<\/p>\n<p><span style=\"text-decoration: underline;\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush:js\">\/\/check download section to see JS code\r\n{\r\n  \"name\": \"teams\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"teams\",\r\n  \"main\": \"main.js\",\r\n  \"scripts\": {\r\n    \"test\": \"test\",\r\n    \"tsc_amd_one\": \"tsc --module amd --outFile GameCompact.js Game.ts\",\r\n    \"tsc_amd\": \"tsc --module amd Game.ts\"\r\n  },\r\n  \"author\": \"dani\",\r\n  \"license\": \"ISC\",\r\n  \"dependencies\": {\r\n    \"typescript\": \"^1.8.10\"\r\n  },\r\n  \"devDependencies\": {}\r\n}\r\n\r\n<\/pre>\n<h2><a name=\"options\"><\/a>7. Options<\/h2>\n<p>TypeScript compiler tsc supports a large list of options and parameters. In this article we only made use of a few of them in order to generate AMD RequireJS compatible modules. If you are interested in all the available options that the TypeScript compiler supports, please visit <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/compiler-options.html\">https:\/\/www.typescriptlang.org\/docs\/handbook\/compiler-options.html<\/a>.<\/p>\n<h2><a name=\"download\"><\/a>8. Download<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nIn the following link you can download a full working example covering the main components explained in this article: <strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/06\/teams.zip\">RequireJSTypeScriptExample<\/a><\/strong><\/div>\n<h2><a name=\"links\"><\/a>9. Links<\/h2>\n<p>The following links contain more information and references about the topics mentioned in this article:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/compiler-options.html\">https:\/\/www.typescriptlang.org\/docs\/handbook\/compiler-options.html<\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/\">https:\/\/www.typescriptlang.org\/<\/a><\/li>\n<li><a href=\"http:\/\/requirejs.org\/\">http:\/\/requirejs.org\/<\/a><\/li>\n<li><a href=\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/requirejs-tutorial-how-to-use-requirejs\/\">https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/requirejs-tutorial-how-to-use-requirejs\/<\/a><\/li>\n<li><a href=\"https:\/\/nodejs.org\/en\/download\/\">https:\/\/nodejs.org\/en\/download\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After that we are going to show how to load these modules using AMD with RequireJS and the TypeScript compiler options to support it. All code and examples used in this &hellip;<\/p>\n","protected":false},"author":134,"featured_media":920,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[340],"tags":[331,76],"class_list":["post-13503","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-requirejs","tag-requirejs","tag-typescript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>TypeScript example using RequireJS - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TypeScript example using RequireJS - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-28T13:15:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-10T14:32:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dani Buiza\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dani Buiza\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\"},\"author\":{\"name\":\"Dani Buiza\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/dedeea4946a1577492c24c5d65515504\"},\"headline\":\"TypeScript example using RequireJS\",\"datePublished\":\"2016-06-28T13:15:03+00:00\",\"dateModified\":\"2018-01-10T14:32:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\"},\"wordCount\":1168,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"keywords\":[\"requireJS\",\"TypeScript\"],\"articleSection\":[\"RequireJS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\",\"name\":\"TypeScript example using RequireJS - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"datePublished\":\"2016-06-28T13:15:03+00:00\",\"dateModified\":\"2018-01-10T14:32:55+00:00\",\"description\":\"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"RequireJS\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/requirejs\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"TypeScript example using RequireJS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/dedeea4946a1577492c24c5d65515504\",\"name\":\"Dani Buiza\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5ad57f031b639d68a6e473652c4907bb6ee1fd4b691e97dff4c14c6ea4d9188c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5ad57f031b639d68a6e473652c4907bb6ee1fd4b691e97dff4c14c6ea4d9188c?s=96&d=mm&r=g\",\"caption\":\"Dani Buiza\"},\"description\":\"Daniel Gutierrez Diez holds a Master in Computer Science Engineering from the University of Oviedo (Spain) and a Post Grade as Specialist in Foreign Trade from the UNED (Spain). Daniel has been working for different clients and companies in several Java projects as programmer, designer, trainer, consultant and technical lead.\",\"sameAs\":[\"http:\/\/danibuiza.github.io\/yo\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/dani-buiza\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TypeScript example using RequireJS - Web Code Geeks - 2026","description":"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After","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:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/","og_locale":"en_US","og_type":"article","og_title":"TypeScript example using RequireJS - Web Code Geeks - 2026","og_description":"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-06-28T13:15:03+00:00","article_modified_time":"2018-01-10T14:32:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","type":"image\/jpeg"}],"author":"Dani Buiza","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Dani Buiza","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/"},"author":{"name":"Dani Buiza","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/dedeea4946a1577492c24c5d65515504"},"headline":"TypeScript example using RequireJS","datePublished":"2016-06-28T13:15:03+00:00","dateModified":"2018-01-10T14:32:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/"},"wordCount":1168,"commentCount":1,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","keywords":["requireJS","TypeScript"],"articleSection":["RequireJS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/","name":"TypeScript example using RequireJS - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","datePublished":"2016-06-28T13:15:03+00:00","dateModified":"2018-01-10T14:32:55+00:00","description":"1. TypeScript with RequireJS In this article we are going to explain how to create a TypeScript application and separate its components in modules. After","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/requirejs\/typescript-example-using-requirejs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"RequireJS","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/requirejs\/"},{"@type":"ListItem","position":4,"name":"TypeScript example using RequireJS"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/dedeea4946a1577492c24c5d65515504","name":"Dani Buiza","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5ad57f031b639d68a6e473652c4907bb6ee1fd4b691e97dff4c14c6ea4d9188c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5ad57f031b639d68a6e473652c4907bb6ee1fd4b691e97dff4c14c6ea4d9188c?s=96&d=mm&r=g","caption":"Dani Buiza"},"description":"Daniel Gutierrez Diez holds a Master in Computer Science Engineering from the University of Oviedo (Spain) and a Post Grade as Specialist in Foreign Trade from the UNED (Spain). Daniel has been working for different clients and companies in several Java projects as programmer, designer, trainer, consultant and technical lead.","sameAs":["http:\/\/danibuiza.github.io\/yo\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/dani-buiza\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/134"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=13503"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13503\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=13503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=13503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=13503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}