You are previewing Learning TypeScript.
O'Reilly logo
Learning TypeScript

Book Description

Exploit the features of TypeScript to develop and maintain captivating web applications with ease

About This Book

  • Learn how to develop modular, scalable, maintainable, and adaptable web applications by taking advantage of TypeScript

  • Create object-oriented JavaScript that adheres to the solid principles efficiently

  • A comprehensive guide that explains the fundamentals of TypeScript with the help of practical examples

  • Who This Book Is For

    If you are a JavaScript developer aiming to learn TypeScript to build beautiful web applications, then this book is for you. No prior knowledge of TypeScript is required.

    What You Will Learn

  • Learn the key TypeScript language features and language runtime

  • Develop modular, scalable, maintainable, and adaptable web applications

  • Create object-oriented code that adheres to the solid principles

  • Save time using automation tools like Gulp and Karma

  • Develop robust applications with testing (Mocha, Chai and SinonJS)

  • Put your TypeScript skills in practice by developing a single-page web application framework from scratch

  • Use the JavaScript of tomorrow (ES6 and ES7) today with TypeScript

  • In Detail

    TypeScript is an open source and cross-platform typed superset of JavaScript that compiles to plain JavaScript that runs in any browser or any host. It allows developers to use the future versions of JavaScript (ECMAScript 6 and 7) today. TypeScript adds optional static types, classes, and modules to JavaScript, to enable great tooling and better structuring of large JavaScript applications.

    This book is a step-by-step guide that will get you started with TypeScript with the help of practical examples. You start off by understanding the basics of TypeScript. Next, automation tools like Grunt are explained followed by a detailed description of function, generics, callbacks and promises. After this, object-oriented features and the memory management functionality of TypeScript are explained. At the end of this book, you will have learned enough to implement all the concepts and build a single page application from scratch.

    Style and approach

    This is a step-by-step guide that covers the fundamentals of TypeScript with practical examples. Each chapter introduces a set of TypeScript language features and leads the readers toward the development of a real-world application.

    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. Learning TypeScript
      1. Table of Contents
      2. Learning TypeScript
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Introducing TypeScript
        1. The TypeScript architecture
          1. Design goals
          2. TypeScript components
        2. TypeScript language features
          1. Types
            1. Optional static type notation
          2. Variables, basic types, and operators
            1. Var, let, and const
            2. Union types
            3. Type guards
            4. Type aliases
            5. Ambient declarations
            6. Arithmetic operators
            7. Comparison operators
            8. Logical operators
            9. Bitwise operators
            10. Assignment operators
          3. Flow control statements
            1. The single-selection structure (if)
            2. The double-selection structure (if…else)
            3. The inline ternary operator (?)
            4. The multiple-selection structure (switch)
            5. The expression is tested at the top of the loop (while)
            6. The expression is tested at the bottom of the loop (do…while)
            7. Iterate on each object's properties (for…in)
            8. Counter controlled repetition (for)
          4. Functions
          5. Classes
          6. Interfaces
          7. Namespaces
        3. Putting everything together
        4. Summary
      10. 2. Automating Your Development Workflow
        1. A modern development workflow
        2. Prerequisites
          1. Node.js
          2. Atom
          3. Git and GitHub
        3. Source control tools
        4. Package management tools
          1. npm
          2. Bower
          3. tsd
        5. Task runners
          1. Checking the quality of the TypeScript code
          2. Compiling the TypeScript code
          3. Optimizing a TypeScript application
          4. Managing the Gulp tasks' execution order
        6. Test runners
        7. Synchronized cross-device testing
        8. Continuous Integration tools
        9. Scaffolding tools
        10. Summary
      11. 3. Working with Functions
        1. Working with functions in TypeScript
          1. Function declarations and function expressions
          2. Function types
          3. Functions with optional parameters
          4. Functions with default parameters
          5. Functions with rest parameters
          6. Function overloading
          7. Specialized overloading signatures
          8. Function scope
          9. Immediately invoked functions
          10. Generics
          11. Tag functions and tagged templates
        2. Asynchronous programming in TypeScript
          1. Callbacks and higher-order functions
          2. Arrow functions
          3. Callback hell
          4. Promises
          5. Generators
          6. Asynchronous functions – async and await
        3. Summary
      12. 4. Object-Oriented Programming with TypeScript
        1. SOLID principles
        2. Classes
        3. Interfaces
        4. Association, aggregation, and composition
          1. Association
          2. Aggregation
          3. Composition
        5. Inheritance
          1. Mixins
        6. Generic classes
        7. Generic constraints
          1. Multiple types in generic type constraints
          2. The new operator in generic types
        8. Applying the SOLID principles
          1. The Liskov substitution principle
          2. The interface segregation principle
          3. The dependency inversion principle
        9. Namespaces
        10. Modules
          1. ES6 modules – runtime and design time
          2. External modules – design time only
          3. AMD modules – runtime only
          4. CommonJS modules – runtime only
          5. UMD modules – runtime only
          6. SystemJS modules – runtime only
        11. Circular dependencies
        12. Summary
      13. 5. Runtime
        1. The environment
        2. The runtime
          1. Frames
          2. Stack
          3. Queue
          4. Heap
          5. The event loop
        3. The this operator
          1. The this operator in the global context
          2. The this operator in a function context
          3. The call, apply, and bind methods
        4. Prototypes
          1. Instance properties versus class properties
          2. Prototypal inheritance
          3. The prototype chain
          4. Accessing the prototype of an object
          5. The new operator
        5. Closures
          1. Static variables with closures
          2. Private members with closures
        6. Summary
      14. 6. Application Performance
        1. Prerequisites
        2. Performance and resources
        3. Performance metrics
          1. Availability
          2. The response time
          3. Processing speed
          4. Latency
          5. Bandwidth
          6. Scalability
        4. Performance analysis
          1. Network performance analysis
          2. Network performance and user experience
            1. Network performance best practices and rules
          3. GPU performance analysis
            1. Frames per second (FPS)
          4. CPU performance analysis
          5. Memory performance analysis
          6. The garbage collector
        5. Performance automation
          1. Performance optimization automation
          2. Performance monitoring automation
          3. Performance testing automation
        6. Exception handling
          1. The Error class
          2. The try…catch statements and throw statements
        7. Summary
      15. 7. Application Testing
        1. Software testing glossary
          1. Assertions
          2. Specs
          3. Test cases
          4. Suites
          5. Spies
          6. Dummies
          7. Stubs
          8. Mocks
          9. Test coverage
        2. Prerequisites
          1. Gulp
          2. Karma
          3. Istanbul
          4. Mocha
          5. Chai
          6. Sinon.JS
          7. Type definitions
          8. PhantomJS
          9. Selenium and Nightwatch.js
        3. Testing planning and methodologies
          1. Test-driven development
          2. Behavior-driven development (BDD)
          3. Tests plans and test types
        4. Setting up a test infrastructure
          1. Building the application with Gulp
          2. Running the unit test with Karma
          3. Running E2E tests with Selenium and Nightwatch.js
        5. Creating test assertions, specs, and suites with Mocha and Chai
          1. Testing the asynchronous code
          2. Asserting exceptions
          3. TDD versus BDD with Mocha and Chai
        6. Test spies and stubs with Sinon.JS
          1. Spies
          2. Stubs
        7. Creating end-to-end tests with Nightwatch.js
        8. Generating test coverage reports
        9. Summary
      16. 8. Decorators
        1. Prerequisites
        2. Annotations and decorators
          1. The class decorators
          2. The method decorators
          3. The property decorators
          4. The parameter decorators
          5. The decorator factory
          6. Decorators with arguments
          7. The reflection metadata API
        3. Summary
      17. 9. Application Architecture
        1. The single-page application architecture
        2. The MV* architecture
        3. Common components and features in the MV* frameworks
          1. Models
          2. Collections
          3. Item views
          4. Collection views
          5. Controllers
          6. Events
          7. Router and hash (#) navigation
          8. Mediator
          9. Dispatcher
          10. Client-side rendering and Virtual DOM
          11. User interface data binding
            1. One-way data binding
            2. Two-way data binding
          12. Data flow
          13. Web components and shadow DOM
        4. Choosing an application framework
        5. Writing an MVC framework from scratch
          1. Prerequisites
          2. Application events
          3. Mediator
          4. Application
          5. Route
          6. Event emitter
          7. Router
          8. Dispatcher
          9. Controller
          10. Model and model settings
          11. View and view settings
          12. Framework
        6. Summary
      18. 10. Putting Everything Together
        1. Prerequisites
        2. The application's requirements
        3. The application's data
        4. The application's architecture
        5. The application's file structure
        6. Configuring the automated build
        7. The application's layout
        8. Implementing the root component
        9. Implementing the market controller
        10. Implementing the NASDAQ model
        11. Implementing the NYSE model
        12. Implementing the market view
        13. Implementing the market template
        14. Implementing the symbol controller
          1. Implementing the quote model
        15. Implementing the symbol view
        16. Implementing the chart model
        17. Implementing the chart view
        18. Testing the application
        19. Preparing the application for a production release
        20. Summary
      19. Index