0%

Book Description

Work with everything you need to create TypeScript applications

Key Features

  • Learn enough about all aspects of TypeScript
  • Answers the questions that new users ask about TypeScript
  • Focus on simple examples and concise explanations

Book Description

TypeScript is designed for the development of large applications and can be used to develop JavaScript applications for both client-side and server-side execution. This book is the ideal introduction to TypeScript, covering both the basics and the techniques you need to build your own applications.

We start by setting up the environment and learning about the build tools that support TypeScript. Then we look at scoping of a variable, and the difference between a undefined variable and a null variable. You will then see the difference between an object, an Object, an object literal, and an object built with a constructor, crucial concepts in understanding TypeScript.

You will learn how to make your code more generic to increase the reusability of your classes, functions, and structures, and to reduce the burden of duplicating code. We look at creating definition files to transform the actual JavaScript code to be compatible with TypeScript.

By the end of the book, you will have worked with everything you need to develop stunning applications using TypeScript.

What you will learn

  • Set up the environment quickly to get started with TypeScript
  • Configure TypeScript with essential configurations that run along your code
  • Structure the code using Types and Interfaces to create objects
  • Demonstrate how to create object-oriented code with TypeScript
  • Abstract code with generics to make the code more reusable
  • Transform the actual JavaScript code to be compatible with TypeScript

Who this book is for

This book is for JavaScript developers who want to get started with TypeScript for building applications. No previous knowledge of TypeScript is expected.

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. Title Page
  2. Copyright and Credits
    1. TypeScript 3.0 Quick Start Guide
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started with TypeScript
    1. Grunt
    2. Gulp
    3. Webpack
    4. NPM/CLI
    5. TypeScript compiler
      1. Files location
        1. rootDir and outDir
        2. baseUrl and paths
        3. sourceRoot and sourceMap and mapRoot
        4. Files and include and exclude
        5. Outfile
      2. Type
        1. typeRoots and types
        2. Declaration and declarationdir
      3. Configuration file
      4. Module and ModuleResolution
      5. ECMAScript
        1. Target
        2. Lib
      6. Compiler strictness
        1. Strict
        2. StrictFunctionTypes
        3. StrictPropertyInitialization and StricNullChecks
    6. Summary
  7. Onboarding Types with Primitive
    1. The difference between var, let, and const
      1. Declaring with var
      2. Declaring with let
      3. const
      4. Enhancing primitives with TypeScript
        1. Number
      5. String
      6. Boolean
      7. Null
      8. Undefined
      9. Symbol
      10. Non-primitive
        1. What is void?
        2. The reasons to avoid using any type
        3. Usage of the never type
        4. Unknown type to have a stricter any type
        5. Enforcing a type in a list
        6. Defining a conscribed set of constants with enum
        7. String literal and its difference compared to a string
      11. Crafting a typed function
    2. How to be strongly typed without specifying the type
    3. Summary
  8. Unleashing the Power of Type with Objects
    1. How to strongly type a set/dictionary with an index signature
    2. TypeScript and map
    3. The differences between index signature and a map
    4. The differences between object and Object
    5. When to use object, Object, or any
    6. What is an object literal?
    7. How to create a constructed object
    8. The differences between an explicit type and a cast
    9. Variable with many types
    10. Combining type with intersect
    11. Intersecting with something other than a type
    12. Intersecting with an optional type
    13. Merge type with inheritance
    14. The differences between type and interface
    15. Destructuring a type and an array
    16. Tuple
    17. The differences between declare and let/const/var
    18. Summary
  9. Transforming Your Code into Object-Oriented
    1. What is a class and how do we define one?
    2. How type comes into play with a class's constructor
    3. What is encapsulation using public, private, and protected
    4. Reducing the definition of a field with a value set at construction time
    5. What is static?
    6. Use cases for a non-public constructor
    7. Using an object from a class versus an object literal
    8. How an interface can be useful in object-oriented
    9. Bringing abstraction with an abstract class
    10. How to have a property that is read-only
    11. Enforcing a specific constructor from an interface
    12. Summary
  10. Scoping Variables with Different Patterns
    1. Comparing at runtime and design time with typeof
    2. Differentiating undefined from null
    3. Getting the type of element in a union 
    4. The limitations of instanceof
    5. Using of a discriminator for type identification
    6. The user-defined guard pattern
    7. The reason to cast a type
    8. What is a type assertion?
    9. Comparing classes
    10. Narrowing type for function with a union in signatures
    11. Summary
  11. Reusing Code Through Generic
    1. Generic code to increase reusability
    2. Accepted kinds of data structure for generic type
    3. Constaining a generic type
    4. Generic and intersection
    5. Default generic
    6. Generic optional type
    7. Generic constraints with a union type
    8. Restricting string choices with keyof
    9. Limiting the access to members of a generic type
    10. Reducing your type creation with mapped type
    11. Generic type in TSX File
    12. Summary
  12. Mastering the Art of Defining Types
    1. How to use a third-party library definition file
    2. How typescript can generate a definition file
    3. How to manually add a definition file for a JavaScript project
    4. How to merge types into an existing definition file
    5. Creating a definition file for a JavaScript project
      1. Definition file for global structure library
      2. Definition file for module library
    6. JavaScript library without a definition file
    7. Using another module from a definition file
    8. Adding a definition file to an extension of an existing module
    9. Summary
  13. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.137.181.52