This is the start of a series of posts where I take a look at aspects of TypeScript's type system that can be referred to as "Advanced". See this as an exploration of TypeScript’s type system past Classes and Interfaces.
A good mental model to have when exploring the advanced part of TypeScript type system is to see it as a more sophisticated mechanism for creating types.
The normal, non-advanced ways of creating types in TypeScript involve using features of the language like type alias, class and interface.
For example these:
interface IPerson {
name: string
age: number
}
type TPerson = {
name: string
age: number
}
class CPerson {
constructor(private name:string, private age: number) {}
getName() {
return this.name;
}
getAge() {
return this.name;
}
}
With the advanced type features, types can be constructed directly or indirectly based on other existing types. How exactly this is done, will be the subject of this series of posts.
The posts in the series include:
- Introduction to Generics in Typescript
- Generic Constraints and More
- Union and Intersection Types
- Literal and Template Literal Types
- Using Literal and Template Literal Types in Typescript
- Overview of Indexable Types in Typescript
- Introduction to Index Types in Typescript
- Tuple Types
- any, unknown, and never types
- Conditional Types
- Mapped Types in Typescript
- Understanding the Magic behind Utility Types in TypeScript
I am writing a book: TypeScript Beyond The Basics. Sign up here to be notified when it is ready.
No comments:
Post a Comment