HTML and CSS Reference
In-Depth Information
Chapter 19
Introduction to TypeScript: Building
a Rogue-like Engine
Jesse Freeman, Developer Evangelist, Amazon
What Is TypeScript?
TypeScript ( http://typescript.org ) is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript
is cross-platform, runs on any browser, and is open source. Microsoft created it, and it's hands down one of the best
languages for building HTML5 games. One of the great things about TypeScript, apart from adding typing to JavaScript,
is that it allows you to start using some of the cool features of ECMAScript 6 (ES6) now, even though it may be years
away from being finalized. This means that you can put to good use classes and other higher-level constructs that you
find in languages such as C# and Java; moreover, TypeScript is incredibly similar to ActionScript 2 and 3. The final key
advantage of TypeScript is that it outputs human readable JavaScript, plus you can use existing JavaScript libraries or
inject the code directly into your TypeScript classes and start taking advantage of typing provided by the compiler.
To help you better understand why TypeScript is so great, I have designed a rogue-like engine for you to build in this
chapter. Rogue engines are one of my favorite things to tinker with because their simplicity lends itself to some creative
ways to manipulate and visualize tile-based levels. In the example, I will walk you through setting up TypeScript, explain
some of the more complex concepts of the language, and show off how—with the help of typing—you can achieve
polymorphism at scale, which is traditionally difficult to do in JavaScript alone. But first, let's go through an overview of
the language itself.
Language Overview
You will find that, out of the gate, TypeScript is incredibly similar to JavaScript. This is good because, when it comes
to picking up TypeScript, the learning curve is rather low. If you have a background in ActionScript, Java, or C#, you
will easily understand the more advanced language features quickly. If not, you will learn a lot from this chapter. At its
core, TypeScript is all about typing. There are three primitive types that you need to know:
var name: string = "Jesse Freeman";
As you can see, you simply use the string type for any strings.
var age: number = 34;
 
Search WWH ::




Custom Search