O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering TypeScript 3 - Third Edition

Book Description

Build enterprise-ready, industrial-strength web applications using TypeScript 3.0 and modern frameworks.

About This Book
  • Enhance your knowledge about language features, asynchronous programming and more.
  • Practical examples that show how to Use TypeScript with modern frameworks.
  • The book covers OOP techniques and design patterns for building applications.
Who This Book Is For

The book is for intermediate/experienced web developers with knowledge of JS and basics of JS who wants to delve into the advanced concepts of TypeScripts and build enterprise-ready web and desktop applications using the only TypeScript at the front and back end. Learn how to use TypeScript with a multitude of modern frameworks, and choose the best framework for your project requirements.

What You Will Learn
  • Gain insights into the core and advanced TypeScript language features
  • Integrate existing JavaScript libraries and third-party frameworks using declaration files
  • Target popular JavaScript frameworks such as jQuery, Backbone, etc
  • Create test suites for your application with Jasmine and Selenium
  • Organize your application code using modules, AMD loaders and SystemJs
  • Explore advanced object-oriented design principles
  • Compare the various MVC implementations in Aurelia, Angular and Backbone
In Detail

TypeScript is both a language and a set of tools to generate JavaScript. This book is an in-depth guide to the TypeScript language and explains how to use its features to build real-world applications. From the beginning, each section builds on previous knowledge in an incremental and easy to understand way. Advanced and powerful language features are all covered, including asynchronous programming techniques, decorators, and generics. With modern frameworks available to the TypeScript programmer, learning forms the foundation of knowledge and is a stepping-stone to effectively building applications using one of them. This book will explore many modern JavaScript & TypeScript frameworks side by side in order for the reader to learn their respective strengths and weaknesses. Best-of-breed applications utilize well-known Design Patterns in order to be scalable, maintainable and testable followed by Object-Oriented techniques and patterns. Finally, we'll build a comprehensive end to end web application to show how these language features, design patterns, and industry best practices can be implemented in a real-world scenario.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Preface
  2. TypeScript - Tools and Framework Options
    1. What is TypeScript?
      1. JavaScript and the ECMAScript Standard
      2. The benefits of TypeScript
        1. Compiling
        2. Strong Typing
          1. TypeScript – syntactic sugar
        3. Type definitions for popular JavaScript libraries.
          1. Definitely Typed
        4. Encapsulation
          1. TypeScript classes generate closures
        5. Public and Private Accessors
    2. TypeScript IDEs
      1. Node based compilation
        1. Creating a tsconfig.json file
        2. Localized Messages
      2. Visual Studio Code
        1. Installing VsCode
        2. Exploring VSCode
          1. Creating a tasks.json file
          2. Building the project
          3. Creating a launch.json file
          4. Setting breakpoints
          5. Debugging web pages
      3. Microsoft Visual Studio
        1. Creating a Visual Studio project
        2. Default project settings
        3. Debugging in Visual Studio
      4. WebStorm
        1. Creating a WebStorm project
        2. Default files
        3. Building a simple HTML application
        4. Running the web page in Chrome
      5. Other editors
        1. Using Grunt
    3. Summary
  3. Types, Variables, and Function Techniques
    1. Basic types
      1. JavaScript typing
      2. TypeScript typing
      3. Type syntax
      4. Inferred typing
      5. Duck typing
      6. Template Strings
      7. Arrays
      8. for...in and for...of
      9. The any type
      10. Explicit casting
      11. Enums
      12. Const enums
      13. String enums
      14. Enum implementation
      15. Const values
      16. The let keyword
      17. Definite Assignment
      18. Dotted property types
      19. Numeric separators
    2. Functions
      1. Function return types
      2. Anonymous functions
      3. Optional parameters
      4. Default parameters
      5. Rest parameters
      6. Function callbacks
      7. Function signatures
      8. Function overrides
      9. Try catch
    3. Advanced Types
      1. Union types
      2. Type guards
      3. Type aliases
      4. Null and undefined
      5. Null operands
        1. Never
        2. Unknown
      6. Object rest and spread
        1. Spread precedence
        2. Rest and spread with arrays
      7. Tuples
        1. Tuple de-structuring
        2. Optional tuple elements
        3. Tuples and rest syntax
    4. Summary
  4. Interfaces, Classes, and Inheritance
    1. Interfaces
      1. Optional properties
      2. Interface compilation
      3. Weak types
      4. Type inference with the in operator
    2. Classes
      1. Class properties
      2. Implementing interfaces
      3. Class constructors
      4. Class functions
      5. Interface function definitions
      6. Class modifiers
      7. Constructor access modifiers
      8. Readonly properties
      9. Class property accessors
      10. Static functions
      11. Static properties
      12. Namespaces
    3. Inheritance
      1. Interface inheritance
      2. Class inheritance
      3. The super keyword
      4. Function overriding
      5. Protected class members
      6. Abstract classes
      7. JavaScript closures
      8. Instanceof
    4. Using interfaces, classes, and inheritance - the Factory Design Pattern
      1. Business requirements
      2. What the Factory Design Pattern does
        1. The IPerson interface
        2. The Person class
        3. Specialist classes
        4. The Factory class
        5. Using the Factory class
    5. Summary
  5. Decorators, Generics, and Asynchronous Features
    1. Decorators
      1. Decorator syntax
      2. Multiple decorators
      3. Decorator factories
      4. Class decorator parameters
      5. Property decorators
      6. Static property decorators
      7. Method decorators
      8. Using method decorators
      9. Parameter decorators
      10. Decorator metadata
      11. Using decorator metadata
    2. Generics
      1. Generic syntax
      2. Instantiating generic classes
      3. Using the type T
      4. Constraining the type of T
      5. Generic interfaces
      6. Creating new objects within generics
    3. Advanced Types with Generics
      1. Conditional Types
      2. Distributed conditional types
      3. Conditional type inference
      4. keyof
      5. keyof with number
      6. Mapped Types
      7. Partial, readonly, Record and Pick
    4. Asynchronous language features
      1. Promises
      2. Promise syntax
      3. Using promises
      4. Callback versus promise syntax
      5. Returning values from promises
      6. Async and await
      7. Await errors
      8. Promise versus await syntax
      9. Await messages
    5. Summary
  6. Declaration Files and Strict Compiler Options
    1. Global variables
    2. Using JavaScript code blocks in HTML
      1. Structured data
    3. Writing your own declaration file
      1. The module keyword
      2. Interfaces
      3. Union types
    4. Module merging
    5. Declaration syntax reference
      1. Function overrides
        1. The JavaScript syntax
        2. The declaration file syntax
      2. Nested namespaces
        1. The JavaScript syntax
        2. The declaration file syntax
      3. Classes
        1. The JavaScript syntax
        2. The declaration file syntax
      4. Class namespaces
        1. The JavaScript syntax
        2. The declaration file syntax
      5. Class constructor overloads
        1. The JavaScript syntax
        2. The declaration file syntax
      6. Class properties
        1. The JavaScript syntax
        2. The declaration file syntax
      7. Class functions
        1. The JavaScript syntax
        2. The declaration file syntax
      8. Static properties and functions
        1. The JavaScript syntax
        2. The declaration file syntax
      9. Global functions
        1. The JavaScript syntax
        2. The declaration file syntax
      10. Function signatures
        1. The JavaScript syntax
        2. The declaration file syntax
      11. Optional properties
        1. The JavaScript syntax
        2. The declaration file syntax
      12. Merging functions and modules
        1. The JavaScript syntax
        2. The declaration file syntax
    6. Strict Compiler Options
      1. noImplicitAny
      2. strictNullChecks
      3. strictPropertyInitialization
      4. noUnusedLocals and noUnusedParameters
      5. noImplicitReturns
      6. noFallthroughCasesInSwitch
    7. Summary
  7. Third-Party Libraries
    1. Using definition files
    2. Using NuGet
      1. Using the Extension Manager
      2. Installing declaration files
      3. Using the Package Manager Console
        1. Installing packages
        2. Searching for package names
        3. Installing a specific version
    3. Using npm and @types
    4. Using third-party libraries
      1. Choosing a JavaScript framework
    5. Backbone
      1. Using inheritance with Backbone
      2. Using interfaces
      3. Using generic syntax
      4. Using ECMAScript 5
      5. Backbone TypeScript compatibility
    6. Angular 1
      1. Angular classes and $scope
      2. Angular 1 TypeScript compatibility
    7. Inheritance - Angular 1 versus Backbone
    8. ExtJs
      1. Creating classes in ExtJs
      2. Using type casting
      3. ExtJs specific TypeScript compiler
    9. Summary
  8. TypeScript Compatible Frameworks
  9. Test Driven Development
  10. Testing Typescript Compatible Frameworks
  11. Modularization
  12. Object-Oriented Programming
  13. Building Applications
  14. Let's Get Our Hands Dirty
  15. Dependency Injection