1. Preface
Put simply, TypeScript is a superset of JavaScript, which means that it builds on top of JavaScript’s mature foundations, adding a variety of helpful syntax and tooling onto the language. It brings the power and productivity of static typing and object-oriented development techniques to the core JavaScript language. In fact, TypeScript is designed to be compiled into fully-compatible JavaScript.
And, as JavaScript’s reach continues to expand, so do the opportunities to leverage TypeScript to create JavaScript-based applications.
In this book, I will show you everything you need to know in order to create full-fledged JavaScript applications using the TypeScript programming language, starting by revisiting some JavaScript fundamentals and proceeding all the way to demonstrating how to convert an entire existing JavaScript codebase to take full advantage of what TypeScript has to offer.
One of the nicest things about TypeScript is that its tooling is fully cross-platform, which means that you can develop TypeScript applications using Windows, Mac, or even Linux. Microsoft even offers an online editor to play around with in order to get your feet wet without having to install anything at all!
What You Should Know
Before getting into the content of the book, I want to take a minute to set some expectations - especially when it comes to what you should already know in order to get the most out of this book.
As I mentioned previously, TypeScript is a superset of JavaScript, which means that it is an extension of JavaScript, adding new features and syntax on top of the core language.
In this book, I’m going to focus the unique features that TypeScript adds to the language rather than explaining the fundamentals of JavaScript itself and I’ll be depending on the assumption that you’ve already got a decent familiarity with the JavaScript language to the point where you should be able to pretty easily recognize where JavaScript ends and TypeScript begins.
In other words, if you’re comfortable using JavaScript to enhance a website to make an AJAX call and update parts of the webpage when the user clicks a button, for example - even if you prefer to use a library like jQuery to help you - you’ll probably be able to follow along with this book just fine.
If, however, you’re relatively new to JavaScript development or don’t have much experience with the language, I strongly suggest you spend some time to learn JavaScript itself first, then come back to this book to see how TypeScript can make your JavaScript experience even more productive.
Source Code Examples
Since this is a book about software development, it’s going to have a lot of code. While I expect you to follow along by running the same code on your local machine, I don’t necessarily expect you to have to copy and paste every character that I show. And, I don’t know about you, but whenever I am having trouble running some sample code that I’m writing along with a book or training course, I always like to have a full, working version of that code that I can refer to in order to help me figure out what I need to change in order to get my version of the code running.
So, to make that possible, I’ve captured a snapshot of the code I show you at the end of every section and it is available to you through my GitHub repository at: github.com/jchadwick/EssentialTypeScript.
You can either browse the repository on the GitHub website or make a local clone of the repository and start looking through it! Note that this repository also contains snapshots at the end of each section, each one represented as a Tag in the repository. That means that if you want to see the code for a specific section, you can switch to that tag in your local repository or select that section from the dropdown on the GitHub site. On the GitHub site, this will change the context of the whole source code tree and you can then use the website to browse through the code as it stands at the end of that section. Also note that you can download a zip archive of any tag as well by visiting the Releases tab and clicking on the “zip” link for the tag that you’d like to download.
The full source code is there if you need it – I encourage you to refer to it as much and as often as you need to in order to get the most out of this book!
Errors, Omissions, and Contributions
Oh, and guess what else is on GitHub – this very book! That’s right - if you head on over to github.com/jchadwick/EssentialTypeScriptBook you’ll find the repository with this full text. From there you’re welcome to submit Issues or even fork the whole thing, make your own changes, and submit a pull request!