TypeScript 3.0 Quick Start Guide

Author: Patrick Desjardins  

Publisher: Packt Publishing‎

Publication year: 2018

E-ISBN: 9781789347937

P-ISBN(Paperback): 89543100482520

Subject: TP312 程序语言、算法语言

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

TypeScript 3.0 Quick Start Guide

Chapter

Grunt

Gulp

Webpack

NPM/CLI

TypeScript compiler

Files location

rootDir and outDir

baseUrl and paths

sourceRoot and sourceMap and mapRoot

Files and include and exclude

Outfile

Type

typeRoots and types

Declaration and declarationdir

Configuration file

Module and ModuleResolution

ECMAScript

Target

Lib

Compiler strictness

Strict

StrictFunctionTypes

StrictPropertyInitialization and StricNullChecks

Summary

Chapter 2: Onboarding Types with Primitive

The difference between var, let, and const

Declaring with var

Declaring with let

const

Enhancing primitives with TypeScript

Number

String

Boolean

Null

Undefined

Symbol

Non-primitive

What is void?

The reasons to avoid using any type

Usage of the never type

Unknown type to have a stricter any type

Enforcing a type in a list

Defining a conscribed set of constants with enum

String literal and its difference compared to a string

Crafting a typed function

How to be strongly typed without specifying the type

Summary

Chapter 3: Unleashing the Power of Type with Objects

How to strongly type a set/dictionary with an index signature

TypeScript and map

The differences between index signature and a map

The differences between object and Object

When to use object, Object, or any

What is an object literal?

How to create a constructed object

The differences between an explicit type and a cast

Variable with many types

Combining type with intersect

Intersecting with something other than a type

Intersecting with an optional type

Merge type with inheritance

The differences between type and interface

Destructuring a type and an array

Tuple

The differences between declare and let/const/var

Summary

Chapter 4: Transforming Your Code into Object-Oriented

What is a class and how do we define one?

How type comes into play with a class's constructor

What is encapsulation using public, private, and protected

Reducing the definition of a field with a value set at construction time

What is static?

Use cases for a non-public constructor

Using an object from a class versus an object literal

How an interface can be useful in object-oriented

Bringing abstraction with an abstract class

How to have a property that is read-only

Enforcing a specific constructor from an interface

Summary

Chapter 5: Scoping Variables with Different Patterns

Comparing at runtime and design time with typeof

Differentiating undefined from null

Getting the type of element in a union 

The limitations of instanceof

Using of a discriminator for type identification

The user-defined guard pattern

The reason to cast a type

What is a type assertion?

Comparing classes

Narrowing type for function with a union in signatures

Summary

Chapter 6: Reusing Code Through Generic

Generic code to increase reusability

Accepted kinds of data structure for generic type

Constaining a generic type

Generic and intersection

Default generic

Generic optional type

Generic constraints with a union type

Restricting string choices with keyof

Limiting the access to members of a generic type

Reducing your type creation with mapped type

Generic type in TSX File

Summary

Chapter 7: Mastering the Art of Defining Types

How to use a third-party library definition file

How typescript can generate a definition file

How to manually add a definition file for a JavaScript project

How to merge types into an existing definition file

Creating a definition file for a JavaScript project

Definition file for global structure library

Definition file for module library

JavaScript library without a definition file

Using another module from a definition file

Adding a definition file to an extension of an existing module

Summary

Other Books You May Enjoy

Index

The users who browse this book also browse