CHAPTER 1
Whenever the word JavaScript is mentioned to a room full of .NET developers, there are visible shudders and uncomfortable fidgeting at the prospect of writing anything in such a sloppy language. I actually love JavaScript, partly because it was the first curly-braced language that I used, but also because I have learned to use it an appropriate way. However, I can understand the reasons for its lack of popularity amongst the .NET community. If you spend most of your time writing code in C#, VB.NET, or F#, the prospect of using a language that lacks sensible autocompletion, type checking, and object-orientation is not a pleasant one—and this is where TypeScript fits perfectly into the tool belt of a .NET programmer.
There are no golden bullets in the world of software development. What is certain is that JavaScript is one of the most widely adopted languages on Earth, and it isn’t likely to be disappearing any time soon, especially given its recent emergence as a high-volume web-server language under the Node.js moniker.
TypeScript eases the pain of JavaScript development by adding some of the features that .NET developers take for granted. It is already smoothly integrated into Visual Studio, which makes it easy to use without switching development tools.
I envisage a future where developers don’t need to write boilerplate JavaScript, not because they are using a framework that includes everything they might need to use, but because they can compose a number of small and reusable modules that take care of specific areas, like AJAX, SVG, and Canvas.
I have written this book primarily for professional .NET developers. TypeScript isn’t exclusively for the .NET domain, as Microsoft has released the language under an open source license and there are plug-ins for Sublime Text, Vim, Emacs, and WebStorm, as well as Visual Studio, which has a fully featured extension. You don’t have to be a JavaScript expert to read this book, but if you would like to learn more about it, you can download JavaScript Succinctly by Cody Lindley from the Syncfusion Technology Resource Portal:
http://www.syncfusion.com/resources/techportal/ebooks
Currently, TypeScript is available as a preview and the language specification is labeled version 0.9. It is likely that the list of features will grow as the TypeScript compiler becomes smarter. Some of the current features haven’t been finalized and are likely to change, and there are further planned features that haven’t yet been written. I have tried to make it clear where a feature is experimental or likely to change, as well as noting alternatives to features that can harm the readability of your code.
All of the examples in this book were created in Visual Studio 2012 using the freely available TypeScript for Visual Studio 2012 extension. Many of the examples can also be tested in the online TypeScript Playground at http://www.typescriptlang.org/Playground/.
In this book, the code samples are shown in code blocks such as the following example.
Code Samples
function log(message) { if (typeof window.console !== 'undefined') { window.console.log(message); } } |
The code samples in this book can be downloaded from https://bitbucket.org/syncfusion/typescript-succinctly.
There are notes that highlight particularly interesting information about a language feature, including potential pitfalls you will want to avoid.
Note: An interesting note about TypeScript.