39,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 732
Veröffentlichungsjahr: 2021
Mastering TypeScript
Fourth Edition
Build enterprise-ready, modular web applications using TypeScript 4 and modern frameworks
Nathan Rozentals
BIRMINGHAM—MUMBAI
Mastering TypeScript
Fourth Edition
Copyright © 2021 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Producers: Aarthi Kumaraswamy, Caitlin Meadows
Acquisition Editor – Peer Reviews: Divya Mudaliar
Project Editor: Janice Gonsalves
Content Development Editor: Alex Patterson
Copy Editor: Safis Editing
Technical Editor: Aniket Shetty
Proofreader: Safis Editing
Indexer: Rekha Nair
Presentation Designer: Ganesh Bhadwalkar
First published: April 2015
Second edition: February 2017
Third edition: February 2019
Fourth edition: April 2021
Production reference: 1210421
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-80056-473-2
www.packt.com
Nathan Rozentals has been writing commercial software for over 30 years in C, C++, Java, and C#.
He picked up TypeScript a week after its initial release in October 2012, and was one of the first people to start blogging about TypeScript, discussing early frameworks such as Backbone, Marionette, ExtJS, and AngularJS.
Nathan's TypeScript solutions now control user interfaces in IoT devices, run as stand-alone applications for point-of-sale solutions, provide complex application configuration for websites, and are used for mission-critical server APIs.
When he is not programming, he is thinking about programming. To stop thinking about programming, he goes windsurfing or plays soccer, or just watches the professionals play soccer. They are so much better at it than he is.
I would like to thank my partner, Kathy, for her unwavering support and love over the years. To Ayron and Daya, I am so proud of you both. To Matt, just keep being yourself.To everyone at Vix, thanks for making work such a gratifying experience. Continue to challenge yourselves, continue to question, and continue to learn. You are all so highly talented, and are fantastic people to work with.
Dan Vanderkam is the author of Effective TypeScript (O'Reilly 2019, now available in Polish!) and a principal software engineer at Sidewalk Labs. He previously worked on open source genome visualizations at Mt. Sinai's Icahn School of Medicine and on search features used by billions of users at Google (try "population of france" or "sunset nyc"). He has a long history of working on open source projects, including the popular dygraphs library and source-map-explorer, a tool for visualizing JavaScript code size. He is also a co-founder of the NYC TypeScript meetup and blogs at effectivetypescript.com. When he's not writing type-safe JavaScript, Dan enjoys playing bridge and rock climbing near his upstate New York home.
Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
Up and Running Quickly
A simple TypeScript IDE
Using npm
Hello TypeScript
Template strings and JavaScript versions
TypeScript project configuration
Watching files for changes
TypeScript basics
Strong typing
Basic types
Inferred typing
Duck typing
Function signatures and void
VS Code IntelliSense
VS Code debugging
Introducing third-party libraries
Declaration files
Summary
Exploring the Type System
any, let, unions, and enums
The any type
Explicit casting
The let keyword
Const values
Union types
Type guards
Type aliases
Enums
String enums
Const enums
More primitive types
Undefined
Null
Conditional expressions
Optional chaining
Nullish coalescing
Null or undefined operands
Definite assignment
Object
Unknown
Never
Never and switch
Object spread
Spread precedence
Spread with arrays
Tuples
Tuple destructuring
Optional tuple elements
Tuples and spread syntax
Object destructuring
Functions
Optional parameters
Default parameters
Rest parameters
Function callbacks
Function signatures as parameters
Function overrides
Literals
Summary
Interfaces, Classes, Inheritance, and Modules
Interfaces
Optional properties
Interfaces are compiled away
Interface naming
Weak types
The in operator
keyof
Classes
The this keyword
Implementing interfaces
Class constructors
Class modifiers
JavaScript private fields
Constructor parameter properties
Readonly
Get and set
Static functions
Static properties
Namespaces
Inheritance
Interface inheritance
Class inheritance
The super function
Function overriding
Protected
Abstract classes
Abstract class methods
instanceof
Interfaces extending classes
Modules
Exporting modules
Importing modules
Module renaming
Multiple exports
Module namespaces
Default exports
Summary
Generics and Advanced Type Inference
Generics
Generic syntax
Multiple generic types
Constraining the type of T
Using the type T
Generic constraints
Generic interfaces
Creating new objects within generics
Advanced type inference
Mapped types
Partial, Readonly, Record, and Pick
Conditional types
Conditional type chaining
Distributed conditional types
Conditional type inference
Type inference from function signatures
Type inference from arrays
Standard conditional types
Summary
Asynchronous Language Features
Callbacks
Promises
Promise syntax
Promise errors
Returning values from Promises
Promise return types
Async and await
Await syntax
Await errors
Await values
Callbacks versus Promises versus async
Summary
Decorators
Decorator overview
Decorator setup
Decorator syntax
Multiple decorators
Types of decorators
Decorator factories
Exploring decorators
Class decorators
Property decorators
Static property decorators
Method decorators
Using method decorators
Parameter decorators
Decorator metadata
Using decorator metadata
Summary
Integration with JavaScript
Declaration files
Global variables
JavaScript code in HTML
Finding declaration files
Writing declaration files
The module keyword
Declaration file typing
Function overloading
Nested namespaces
Classes
Static properties and functions
Abstract classes
Generics
Conditional types
Conditional type inference
Declaration file summary
Integration compiler options
The allowJs and outDir options
Compiling JavaScript
The declaration option
Summary
Strict Compiler Options
Nested configuration
Strict Options
strictNullChecks
strictPropertyInitialization
strictBindCallApply
strictFunctionTypes
no compiler options
noImplicitAny
noUnusedLocals and noUnusedParameters
noImplicitReturns
noFallthroughCasesInSwitch
noImplicitThis
Summary
Using Observables to Transform Data
Introduction to Observables
pipe and map
Combining operators
Avoid swallowing values
Time-based Observables
Observable errors
catchError
Observables returning Observables
mergeMap
concatMap
forkJoin
Observable Subject
Summary
Test-Driven Development
The testing paradigm
Unit, integration, and acceptance tests
Unit tests
Integration tests
Acceptance tests
Unit testing frameworks
Jest
ts-jest
Watch mode
Grouping tests
Forcing and skipping tests
Matchers
Test setup and teardown
Data-driven tests
Jest mocks
Jest spies
Spies returning values
Asynchronous tests
Using done
Using async await
HTML-based tests
DOM events
Protractor
Selenium
Finding page elements
Summary
Angular
Angular setup
Application structure
Angular modules
Angular Material
A shared module
An Angular application
Angular DOM events
Angular EventEmitter
Angular services
Angular Dependency Injection
Child components
Angular forms
Reactive forms
Reactive form templates
Reading form values
Angular unit testing
Unit testing forms
Reacting to domain events
Summary
React
Introduction to React
React setup
JSX
JSX and logic
React props
React event handling
React state
A React application
Application overview
Mechanical keyboard switches
Application components
The CollectionView component
The ItemView component
The DetailView component
The App component
React forms
Summary
Vue
Introduction to Vue
Vue setup
Component structure
Child components and props
Component state
Component events
Computed props, conditionals, and loops
A Vue application
Application overview
Material Design for Bootstrap
App component
ShoppingCart component
ItemView component
CheckoutView component
ItemTotalView component
Summary
Node and Express
Express introduction
Express setup
Express router
Express configuration
An Express application
Express templating
Handlebars configuration
Using templates
Static files
Express forms
Express session data and redirects
Summary
An AWS Serverless API
Serverless setup
AWS Lambda architecture
Installing the SAM CLI
Initializing a SAM application
Generated structure
Deploying a SAM application
Building an API
DynamoDB tables
NoSQL Workbench
Application API endpoints
A Lambda function
Compiling Lambdas
Running Lambdas locally
Lambda path parameters
Processing database records
API summary
Summary
Micro Front-ends
Design concepts
Micro front-end mechanisms
The iframe technique
The JavaScript technique
The Registry technique
What we will use
Communication mechanisms
Domain events
The Event Bus
Building a micro front-end application
The global Event Bus
Building a module
Module typing
React updates
Loading data from an API
React domain events
Vue updates
Vue domain events
Fetching data in Vue
Raising Events
Angular micro front-end
Micro front-end DOM Containers
Rendering the React front-end
Rendering the Vue front-end
Angular domain events
Our micro front-end application
Thoughts on micro front-ends
Summary
Other Books You May Enjoy
Index
Cover
Index
