This book consists of two parts:
- Part 1 is a quick start for TypeScript that teaches you the essentials quickly.
- Part 2 digs deeper into the language and covers many important topics in detail.
This book is not a reference, it is meant to complement the official TypeScript handbook.
- Title
- Tackling TypeScript
- Subtitle
- Upgrading from JavaScript
- Author(s)
- Dr. Axel Rauschmayer
- Published
- 2020
- Edition
- 1
- Format
- eBook (pdf, epub, mobi)
- Pages
- 230
- Language
- English
- License
- Read online for free
- Book Homepage
- Free eBook, Errata, Code, Solutions, etc.
I Preliminaries About this book Where is the homepage of this book? What is in this book? What do I get for my money? How can I preview the content? How do I report errors? What do the notes with icons mean? Acknowledgements Why TypeScript? The benefits of using TypeScript The downsides of using TypeScript TypeScript myths Free resources on TypeScript II Getting started with TypeScript How does TypeScript work? The bird's eye view The structure of TypeScript projects Programming TypeScript via an integrated development environment (IDE) Other files produced by the TypeScript compiler Using the TypeScript compiler for plain JavaScript files Trying out TypeScript The TypeScript Playground TS Node Notation used in this book Test assertions (dynamic) Type assertions (static) The essentials of TypeScript What you'll learn Specifying the comprehensiveness of type checking Types in TypeScript Type annotations Type inference Specifying types via type expressions The two language levels: dynamic vs. static Type aliases Typing Arrays Function types Union types Optional vs. default value vs. undefined|T Typing objects Type variables and generic types Example: a generic class Conclusion: understanding the initial example Creating CommonJS-based npm packages via TypeScript Required knowledge Limitations The repository ts-demo-npm-cjs .gitignore .npmignore package.json tsconfig.json TypeScript code Creating web apps via TypeScript and webpack Required knowledge Limitations The repository ts-demo-webpack package.json webpack.config.js tsconfig.json index.html main.ts Installing, building and running the web app Using webpack without a loader: webpack-no-loader.config.js Strategies for migrating to TypeScript Three strategies Strategy: mixed JavaScript/TypeScript code bases Strategy: adding type information to plain JavaScript files Strategy: migrating large projects by snapshot testing the TypeScript errors Conclusion III Basic types What is a type in TypeScript? Two perspectives Three questions for each perspective Perspective 1: types are sets of values Perspective 2: type compatibility relationships Nominal type systems vs. structural type systems Further reading The top types any and unknown TypeScript's two top types The top type any The top type unknown TypeScript enums: How do they work? What can they be used for? The basics Specifying enum member values (advanced) Downsides of numeric enums Use cases for enums Enums at runtime const enums Enums at compile time Acknowledgment Alternatives to enums in TypeScript Unions of singleton values Discriminated unions Object literals as enums Enum pattern Summary of enums and enum alternatives Acknowledgement Adding special values to types Adding special values in band Adding special values out of band IV Types for objects, classes, Arrays, and functions Typing objects Roles played by objects Types for objects Object vs. object in TypeScript Object type literals and interfaces Type inference Other features of interfaces JavaScript's prototype chains and TypeScript's types Sources of this chapter Class definitions in TypeScript Cheat sheet: classes in plain JavaScript Non-public data slots in TypeScript Private constructors Initializing instance properties Abstract classes Class-related types The two prototype chains of classes Interfaces for instances of classes Interfaces for classes Classes as types Further reading Types for classes as values Types for specific classes The type operator typeof A generic type for classes: Class Typing Arrays Roles of Arrays Ways of typing Arrays Pitfall: type inference doesn't always get Array types right Pitfall: TypeScript assumes indices are never out of bounds Typing functions Defining statically typed functions Types for functions Parameters Overloading (advanced) Assignability (advanced) Further reading and sources of this chapter V Dealing with ambiguous types Type assertions (related to casting) Type assertions Constructs related to type assertions Type guards and assertion functions When are static types too general? Narrowing via built-in type guards User-defined type guards Assertion functions Quick reference: user-defined type guards and assertion functions Alternatives to assertion functions @hqoss/guards: library with type guards Validating external data JSON schema Approaches for data validation in TypeScript Example: validating data via the library Zod Conclusion VI Miscellaneous An overview of computing with types Types as metavalues Generic types: factories for types Union types and intersection types Control flow Various other operators
Related Books