Book Image

Mastering TypeScript

By : Nathan Rozentals
Book Image

Mastering TypeScript

By: Nathan Rozentals

Overview of this book

<p>The TypeScript compiler and language has brought JavaScript development up to the enterprise level, yet still maintains backward compatibility with existing JavaScript browsers and libraries.</p> <p>Packed with practical code samples, this book brings the benefits of strongly typed, object-oriented programming and design principles into the JavaScript development space. Starting with core language features, and working through more advanced topics such as generics and modules, you will learn how to gain maximum benefit from your JavaScript development with TypeScript. With a strong focus on test-driven development and coverage of many popular JavaScript frameworks, you can fast-track your TypeScript knowledge to a professional level. By the end of this book, you will be able to confidently implement a TypeScript application from scratch.</p>
Table of Contents (17 chapters)
Mastering TypeScript
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
TypeScript – Tools and Framework Options
2
Types, Variables and Function Techniques
Index

Chapter 4. Writing and Using Declaration Files

One of the most appealing facets of JavaScript development is the myriad of external JavaScript libraries that have already been published, such as jQuery, Knockout, and Underscore. The TypeScript designers knew that introducing "syntactic sugar" to the TypeScript language would bring a range of benefits to the developer experience. These benefits include IDE features such as Intellisense, as well as detailed compile time error messages. We have already seen how to use this syntax for most of the TypeScript language features such as classes, interfaces, and generics, but how do we apply this "sugar" to existing JavaScript libraries? The answer is relatively simple—declaration files.

A declaration file is a special type of file used by the TypeScript compiler. It is marked with a .d.ts extension, and is then used by the TypeScript compiler within the compilation step. Declaration files are similar to header files used in other languages; they...