Mastering TypeScript - Fourth Edition

Book description

Learn all you need to know to work with TypeScript, explore modern web application frameworks, and build modular systems using industry standard architectural principles and design patterns

Key Features

  • Explore TypeScript 4's key elements and advanced language features
  • Use TypeScript with modern frameworks such as Angular, Vue, React, RxJS and Node
  • Understand TDD, serverless techniques, micro frontends, and other industry-standard best practices to create high-quality and modular apps

Book Description

TypeScript is both a language and a set of tools to generate JavaScript, designed by Anders Hejlsberg at Microsoft to help developers write enterprise-scale JavaScript.

Mastering Typescript is a golden standard for budding and experienced developers. With a structured approach that will get you up and running with Typescript quickly, this book will introduce core concepts, then build on them to help you understand (and apply) the more advanced language features. You'll learn by doing while acquiring the best programming practices along the way.

This fourth edition also covers a variety of modern JavaScript and TypeScript frameworks, comparing their strengths and weaknesses. You'll explore Angular, React, Vue, RxJs, Express, NodeJS, and others. You'll get up to speed with unit and integration testing, data transformation, serverless technologies, and asynchronous programming. Next, you'll learn how to integrate with existing JavaScript libraries, control your compiler options, and use decorators and generics.

By the end of the book, you will have built a comprehensive set of web applications, having integrated them into a single cohesive website using micro front-end techniques. This book is about learning the language, understanding when to apply its features, and selecting the framework that fits your real-world project perfectly.

What you will learn

  • Gain insights into core and advanced TypeScript language features
  • Integrate with existing JavaScript libraries and third-party frameworks
  • Build full working applications using JavaScript frameworks, such as Angular, React, Vue, and more
  • Create test suites for your application with Jest and Selenium
  • Apply industry-standard design patterns to build modular code
  • Develop web server solutions using NodeJS and Express
  • Design and implement serverless API solutions
  • Explore micro front-end technologies and techniques

Who this book is for

If you are keen to learn TypeScript, this book will give you all the necessary knowledge and skills to tackle any TypeScript project. It will also give you an understanding of what application frameworks are out there, and which one to choose for your next project. If you are already an experienced JS or TypeScript developer, then this book will take your skills to the next level. No JS experience is required to get started — we'll teach you all you need to know.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Up and Running Quickly
    1. A simple TypeScript IDE
      1. Using npm
      2. Hello TypeScript
      3. Template strings and JavaScript versions
      4. TypeScript project configuration
      5. Watching files for changes
    2. TypeScript basics
      1. Strong typing
      2. Basic types
      3. Inferred typing
      4. Duck typing
      5. Function signatures and void
      6. VS Code IntelliSense
      7. VS Code debugging
      8. Introducing third-party libraries
      9. Declaration files
    3. Summary
  3. Exploring the Type System
    1. any, let, unions, and enums
      1. The any type
      2. Explicit casting
      3. The let keyword
      4. Const values
      5. Union types
      6. Type guards
      7. Type aliases
      8. Enums
        1. String enums
        2. Const enums
    2. More primitive types
      1. Undefined
      2. Null
      3. Conditional expressions
      4. Optional chaining
      5. Nullish coalescing
      6. Null or undefined operands
      7. Definite assignment
      8. Object
      9. Unknown
      10. Never
      11. Never and switch
    3. Object spread
      1. Spread precedence
      2. Spread with arrays
    4. Tuples
      1. Tuple destructuring
      2. Optional tuple elements
      3. Tuples and spread syntax
      4. Object destructuring
    5. Functions
      1. Optional parameters
      2. Default parameters
      3. Rest parameters
      4. Function callbacks
      5. Function signatures as parameters
      6. Function overrides
      7. Literals
    6. Summary
  4. Interfaces, Classes, Inheritance, and Modules
    1. Interfaces
      1. Optional properties
      2. Interfaces are compiled away
      3. Interface naming
      4. Weak types
      5. The in operator
      6. keyof
    2. Classes
      1. The this keyword
      2. Implementing interfaces
      3. Class constructors
      4. Class modifiers
      5. JavaScript private fields
      6. Constructor parameter properties
      7. Readonly
      8. Get and set
      9. Static functions
      10. Static properties
      11. Namespaces
    3. Inheritance
      1. Interface inheritance
      2. Class inheritance
      3. The super function
      4. Function overriding
      5. Protected
      6. Abstract classes
      7. Abstract class methods
      8. instanceof
      9. Interfaces extending classes
    4. Modules
      1. Exporting modules
      2. Importing modules
      3. Module renaming
      4. Multiple exports
      5. Module namespaces
      6. Default exports
    5. Summary
  5. Generics and Advanced Type Inference
    1. Generics
      1. Generic syntax
      2. Multiple generic types
      3. Constraining the type of T
      4. Using the type T
      5. Generic constraints
      6. Generic interfaces
      7. Creating new objects within generics
    2. Advanced type inference
      1. Mapped types
      2. Partial, Readonly, Record, and Pick
      3. Conditional types
      4. Conditional type chaining
      5. Distributed conditional types
      6. Conditional type inference
      7. Type inference from function signatures
      8. Type inference from arrays
      9. Standard conditional types
    3. Summary
  6. Asynchronous Language Features
    1. Callbacks
    2. Promises
      1. Promise syntax
      2. Promise errors
      3. Returning values from Promises
      4. Promise return types
    3. Async and await
      1. Await syntax
      2. Await errors
      3. Await values
    4. Callbacks versus Promises versus async
    5. Summary
  7. Decorators
    1. Decorator overview
      1. Decorator setup
      2. Decorator syntax
      3. Multiple decorators
      4. Types of decorators
      5. Decorator factories
    2. Exploring decorators
      1. Class decorators
      2. Property decorators
      3. Static property decorators
      4. Method decorators
      5. Using method decorators
      6. Parameter decorators
      7. Decorator metadata
      8. Using decorator metadata
    3. Summary
  8. Integration with JavaScript
    1. Declaration files
      1. Global variables
      2. JavaScript code in HTML
      3. Finding declaration files
      4. Writing declaration files
      5. The module keyword
    2. Declaration file typing
      1. Function overloading
      2. Nested namespaces
      3. Classes
      4. Static properties and functions
      5. Abstract classes
      6. Generics
      7. Conditional types
      8. Conditional type inference
      9. Declaration file summary
    3. Integration compiler options
      1. The allowJs and outDir options
      2. Compiling JavaScript
      3. The declaration option
    4. Summary
  9. Strict Compiler Options
    1. Nested configuration
    2. Strict Options
      1. strictNullChecks
      2. strictPropertyInitialization
      3. strictBindCallApply
      4. strictFunctionTypes
    3. no compiler options
      1. noImplicitAny
      2. noUnusedLocals and noUnusedParameters
      3. noImplicitReturns
      4. noFallthroughCasesInSwitch
      5. noImplicitThis
    4. Summary
  10. Using Observables to Transform Data
    1. Introduction to Observables
      1. pipe and map
      2. Combining operators
      3. Avoid swallowing values
      4. Time-based Observables
    2. Observable errors
      1. catchError
    3. Observables returning Observables
      1. mergeMap
      2. concatMap
      3. forkJoin
    4. Observable Subject
    5. Summary
  11. Test-Driven Development
    1. The testing paradigm
      1. Unit, integration, and acceptance tests
        1. Unit tests
        2. Integration tests
        3. Acceptance tests
      2. Unit testing frameworks
    2. Jest
      1. ts-jest
        1. Watch mode
        2. Grouping tests
        3. Forcing and skipping tests
      2. Matchers
      3. Test setup and teardown
      4. Data-driven tests
      5. Jest mocks
      6. Jest spies
        1. Spies returning values
    3. Asynchronous tests
      1. Using done
      2. Using async await
    4. HTML-based tests
      1. DOM events
    5. Protractor
      1. Selenium
      2. Finding page elements
    6. Summary
  12. Angular
    1. Angular setup
      1. Application structure
      2. Angular modules
      3. Angular Material
      4. A shared module
    2. An Angular application
      1. Angular DOM events
      2. Angular EventEmitter
      3. Angular services
      4. Angular Dependency Injection
      5. Child components
    3. Angular forms
      1. Reactive forms
      2. Reactive form templates
      3. Reading form values
      4. Angular unit testing
      5. Unit testing forms
      6. Reacting to domain events
    4. Summary
  13. React
    1. Introduction to React
      1. React setup
      2. JSX
      3. JSX and logic
      4. React props
      5. React event handling
      6. React state
    2. A React application
      1. Application overview
        1. Mechanical keyboard switches
      2. Application components
      3. The CollectionView component
      4. The ItemView component
      5. The DetailView component
      6. The App component
      7. React forms
    3. Summary
  14. Vue
    1. Introduction to Vue
      1. Vue setup
      2. Component structure
      3. Child components and props
      4. Component state
      5. Component events
      6. Computed props, conditionals, and loops
    2. A Vue application
      1. Application overview
      2. Material Design for Bootstrap
      3. App component
      4. ShoppingCart component
      5. ItemView component
      6. CheckoutView component
      7. ItemTotalView component
    3. Summary
  15. Node and Express
    1. Express introduction
      1. Express setup
      2. Express router
      3. Express configuration
    2. An Express application
      1. Express templating
      2. Handlebars configuration
      3. Using templates
      4. Static files
      5. Express forms
      6. Express session data and redirects
    3. Summary
  16. An AWS Serverless API
    1. Serverless setup
      1. AWS Lambda architecture
      2. Installing the SAM CLI
      3. Initializing a SAM application
      4. Generated structure
      5. Deploying a SAM application
    2. Building an API
      1. DynamoDB tables
      2. NoSQL Workbench
      3. Application API endpoints
      4. A Lambda function
      5. Compiling Lambdas
      6. Running Lambdas locally
      7. Lambda path parameters
      8. Processing database records
      9. API summary
    3. Summary
  17. Micro Front-ends
    1. Design concepts
      1. Micro front-end mechanisms
        1. The iframe technique
        2. The JavaScript technique
        3. The Registry technique
        4. What we will use
      2. Communication mechanisms
      3. Domain events
      4. The Event Bus
    2. Building a micro front-end application
      1. The global Event Bus
        1. Building a module
        2. Module typing
      2. React updates
        1. Loading data from an API
        2. React domain events
      3. Vue updates
        1. Vue domain events
        2. Fetching data in Vue
        3. Raising Events
      4. Angular micro front-end
        1. Micro front-end DOM Containers
        2. Rendering the React front-end
        3. Rendering the Vue front-end
        4. Angular domain events
        5. Our micro front-end application
      5. Thoughts on micro front-ends
    3. Summary
  18. Other Books You May Enjoy
  19. Index

Product information

  • Title: Mastering TypeScript - Fourth Edition
  • Author(s): Nathan Rozentals
  • Release date: April 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800564732