Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

At the same time, I participated in the Digitalstar project to win the creative gift package and challenge the creative incentive money

preface

Preliminary review

Getting started with TypeScript development environment and preparation

The basics of TypeScript

Getting started with TypeScript

Type of operation

Mapped Type (Mapped Type)

Combine the mapping type + keyof + Typeof + optional + read-only modifier

Template literal types (TS4.1)

Template literal types were introduced in TS4.1. It makes it easier to create string literal types. The syntax is the same as template strings in JS.

contrast: template stringVSTemplate literals

Condition type (TS2.8)

Condition types were introduced in TS2.8. To put it simply, conditional typing is to return different types by judging the relationship between two types. Syntax and the ternary operator (X? A: B)

contrast: ternary operatorVSConditions in theOther languages have similar features for conditional types. For example, in C++, this can be done through template specialization.

Conditional types Advanced topics:

  • Distributive Conditional Types in Conditional Types

  • Infer the keyword

  • UnionToIntersection<U>

  • Type variable Variance

Common Tool Types

lib.es5.d.ts

conclusion

analogyYou can think of TS’s type system itself as a “language” for manipulating and creating types:

  • List ←→ Execute in sequence

  • Mapping type ←→ loop

  • Condition type ←→ Condition judgment

JS operates on various values, which have corresponding various operations

TS operates on types, and types are sets, and sets have operations on sets

What are you doing with TS?

The “language” we provide through the TS type system describes exactly what types we need. What TS does in return is expose problems ahead of compile time. The code is more robust and extensible.

The TypeScript resources

Books

Links

TypeScript official TypeScript documentation

  • Read through.

  • Key Handbook, focus on What’s New

Understanding TypeScript online

  • Read through the

Nuggets: articles, columns, pamphlets

The TypeScript column

StackOverflow

  • Don’t understand to ask

  • Attach a link to the Playground with your questions

TypeScript source code, Issue, PR

TypeScript

conclusion

If there is any mistake above, please point out in the comment section, thank you!

After reading it, give it a thumbs-up and then walk away