“This is the second day of my participation in the November Gwen Challenge. See details of the event: The last Gwen Challenge 2021”.

Review the

In chapter 1, we learned how to read ts documentation, which should make the English version less scary.

Review of previous section: From 0 Ts 01- Document Reading

Eyery Types

Tips: Notice the index table on the right when looking at the document

Now let’s move on to Chapter 2 and look at common types. Also, let’s see if the documentation tells us any tricks beyond the usual function points.

The primitives: string, number, Boolean

The most basic value type,

  • String string
  • The number of digital
  • Boolean Boolean

Arrys array type

There are two ways to write an array type

any

When a value is any, you can access any of its properties without error.

noImplicitAny

This type marks the implied any type as an error.

Type Annotations on Variables

The type tag

Functions

methods

Function can specify the type of input and output of a Function.

Parameter Type Annotations

Type parameter comment

Return Type Annotations

Return type comment

Anonymous Functions

Anonymous functions

When a function appears where you can determine how to call it, the function’s arguments are automatically given types.

It automatically determines whether S has the toUppercased method.

Object Types Object Types

The PT section is a demonstration of object types

Optional Properties

Optional attribute

Union Types

The union type

Based on the base types above, we can begin to compose the base types.

Defining a Union Type

Defining union types

The first way to combine types is to combine types. As the name implies, a union type is a type composed of two or more other member types, representing a value that may be any one of them. We can call each of these types union’s menbers.

Working with Union Types

Work with union types

There is a small rule here where the type value rule performs code narrowing union, or type contraction (intersection of code types). Ex. :

Type Aliases

Type the alias

Interfaces interface

An interface is another form of named object type.

Interface inheritance is also possible

The difference between type and interface

Interface: inheritable, adding new fields to an existing Interface

Type: Extends types by intersections

Type Assertions

Types of assertions

Type assertions can be written in two ways

Literal Types

Text type

The “XXX” text can also be used as a type description

Literal Interface

Literally reasoning

A variable definition that does not set a type does argument reasoning based on the assigned value

null and undefined

strictNullChecks

Off Disables null verification

On Performs strict verification

Non-null Assertion Operator

Non-empty assertion operator, suffix (!)

Enum enumerated values

It will be described in a separate section

Less Common Primitives

Bigint big integer

Symbol Globally unique symbol reference

— END —

The next section describes the ts-03 Function type starting from 0