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 2. Types, Variables and Function Techniques

TypeScript introduces strong typing to JavaScript through a simple syntax, referred to by Anders Hejlsberg as "syntactic sugar".

This chapter is an introduction to the syntax used in the TypeScript language to apply strong typing to JavaScript. It is intended for readers that have not used TypeScript before, and covers the transition from standard JavaScript to TypeScript. If you already have experience with TypeScript, and have a good understanding of the topics listed below, then by all means have a quick read through, or skip to the next chapter.

We will cover the following topics in this chapter:

  • Basic types and type syntax: strings, numbers, and booleans

  • Inferred typing and duck-typing

  • Arrays and enums

  • The any type and explicit casting

  • Functions and anonymous functions

  • Optional and default function parameters

  • Argument arrays

  • Function callbacks and function signatures

  • Function scoping rules and overloads