background preloader


Facebook Twitter

TypeScript Modules Demystified : Internal, AMD with RequireJS, CommonJS with NodeJS. TypeScript: Organizing your code with AMD modules and require.js. TypeScript has two methods of generating JavaScript output files: CommonJS, and AMD.

TypeScript: Organizing your code with AMD modules and require.js

CommonJS is the default, and amd modules can be generated by adding the –module AMD option to the compiler flags. In this post, I’ll show how to create and use AMD modules, as well as configuring require.js by using require.config. Update This article has been updated to use TypeScript 0.9. You can download / browse the source at github/blorkfish/typescript-amd-require-0.9 The older 0.8.1 source for this solution can be found here. The older 0.8.0 source for this solution can be found here Creating a default project using CommonJS Let’s start with a standard new TypeScript project – which by default creates an app.ts file, and a default.htm – and add the following: \modules\Require.d.ts As at the time of update, this is at version 2.1.1. \app\classes\Greeter.ts as an AMD module Cut the code defining the Greeter class from \app.ts into the \app\classes\Greeter.ts file:

Introducing TypeScript. Unless you’ve been hiding under a bush all week, you’ve no doubt encountered TypeScript; Microsoft’s new language for application-scale JavaScript development.

Introducing TypeScript

There’s plenty of mis-information flying around, so I thought I’d join in… Modularization in TypeScript. UPDATE: Check out the new GitHub project that accompanies this post: TypeScript Modularization Demo.

Modularization in TypeScript

In my last post, I introduced TypeScript, Microsoft’s new offering which layers static typing on top of JavaScript. Today I’d like to go further and discuss modularization and code organization. TypeScript has the ability to take advantage of a pair of JavaScript modularization standards – CommonJS and Asynchronous Module Definition (AMD). These capabilities allow for projects to be organized in a manner similar to what a “mature,” traditional server-side OO language provides. This is particularly useful for the most likely candidates for TypeScript – large Web Applications. Although TypeScript’s modularization is powerful, it requires some background knowledge of CommonJS and AMD, and has its pitfalls. On the State of Modularization in JavaScript Organizing scripts in JavaScript-based web apps has historically been a thorny issue. Okay, so that’s a bit of a dramatization. Borisyankov/DefinitelyTyped. TypeScript strongly typed Backbone Models.

TypeScript and Backbone are a great fit in terms of writing simple, Object-Oriented code using JavaScript.

TypeScript strongly typed Backbone Models

The simplicity of Backbone, coupled with the TypeScript generated closure syntax allow one to simply use the TypeScript extends keyword to derive from any of Backbone’s base classes – and start implementing functionality immediately. This is a very natural way to write Object-Oriented JavaScript: class ListItem extends Backbone.Model { } The problem with Backbone Models Unfortunately, Backbone uses object attributes to store Model properties, and these need to be set in order for the Backbone model to work correctly.

Class ListItem extends Backbone.Model { constructor() { super(); this.set('Id', '2'); } } The nature of the set and get functions of Backbone, however do not have any inherent type-safety. Using ES5 getter and setter syntax The above effect can be achieve by using ES5 getter and setter syntax. Model Type-safety Consider the following code: Simplifying the constructor. 7 Months with TypeScript. Since December 2012, I have used TypeScript as my primary language while working on a large scale enterprise project due to ship next month.

7 Months with TypeScript

I want to share the details on how we are using TypeScript as a team and our workflow that has made our project a success. TypeScript is an open source language and compiler written by Microsoft that runs on NodeJS. The language is based on the evolving ES6 spec but adds support for types, interfaces that generates JavaScript (ES3 or ES5 dialects based on flag). TypeScript Language Specification. TypeScript. TypeScript is a strict superset of JavaScript, so any existing JavaScript programs are also valid TypeScript programs.


TypeScript is designed for development of large applications and compiles down to JavaScript.[5] TypeScript supports header files which can contain type information of existing JavaScript libraries, enabling other programs to use objects defined in the header files as if they were strongly typed TypeScript objects. There are third-party header files for popular libraries like jQuery, MongoDB, Node.js, and D3.js.[6] Background[edit] TypeScript originates from the need to develop large-scale JavaScript applications. Internally at Microsoft the challenges with dealing with complex JavaScript code led to demand for custom tooling to ease the writing of components in the language.[8] Microsoft has stated that they did not have the intention of making something that could break compatibility with the standard and its cross-platform support.

Language features[edit] Classes[edit] TypeScript - Home. Welcome to TypeScript.