Skip to content

Commit 1a7107c

Browse files
committed
Update the-data.md
1 parent 6891d4f commit 1a7107c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

01-the-data/the-data.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# The data of type-level programs
22

3-
Like with every programming language, in Type-Level TypeScript we will write programs that **transform some data** but unlike in other programming languages, the data our programs will transform are **types**!
3+
Like with every programming language, in Type Level Typescript we will write code that **transform some data**. The only thing that's different from most other languages is that the data our code will transform are **types**! We will write programs that take some types as input and output some other types.
44

5-
We will write code that take some types as input and output other types. To master this language we will need to start by understanding the different sorts of data we have at our disposal.
5+
To master this language we will need to start by understanding the different sorts of data we have at our disposal.
66

77
## The three families of types
88

99
There are 3 main "families" of data in Type-Level TypeScript (TLTS): primitive types, literal types, and data structure types. Let's explore each of them.
1010

1111
### Primitive types
1212

13-
You are certainly already familiar with primitive types. We use them a lot to annotate our function arguments and return types in our day to day TypeScript code. Here is the list of primitive types:
13+
You are certainly already familiar with primitive types. We use them a lot to annotate our variables and functions in our day to day TypeScript code. Here is the list of primitive types:
1414

1515
```ts
1616
type Primitives =
@@ -27,7 +27,7 @@ Every JavaScript value at the exception of objects and functions belong to one o
2727

2828
### Literal types
2929

30-
Literal types are "exact" types, which encompass a **single value**.
30+
Literal types are "exact" types, which encompass a **single possible value**.
3131

3232
<!-- prettier-ignore -->
3333
```ts
@@ -50,39 +50,39 @@ There's an infinite number of literal types and they look just like regular valu
5050

5151
The world of values and the world of types mostly belong to two parallel universes which exist separately but can't "touch" each other and can't be mixed together [(1)](#dependent-types). I think it's helpful to consider literal types as a sort of reflection of values in the world of types, but we need to keep in mind that they are different things.
5252

53-
One notable difference between values and literal types is that you can't write arithmetic expressions at the type-level. For instance `type five = 2 + 3` won't work, even if `const five = 2 + 3` is a perfectly valid value-level expression.
53+
One notable difference between values and literal types is that you can't write arithmetic expressions at the type-level. For instance `type five = 2 + 3` won't work, even if `const five = 2 + 3` is a perfectly valid piece of value-level code.
5454

55-
Literal types become particarly useful when put in unions to describe variables which can only contain a finite set of possible values, like `let trafficLight: "green" | "orange" | "red";`. We will explore union types in more depths in a bit.
55+
Literal types become particarly useful when put in unions to describe variables which can only contain a finite set of possible values like `let trafficLight: "green" | "orange" | "red";`. We will explore union types in more depths in a bit.
5656

5757
### Data structures
5858

5959
In our type-level world, we have four main built-in data structures at our disposal: objects, records, tuples and arrays.
6060

6161
```ts
6262
type DataStructures =
63-
| { key1: 1; key2: 2 } // objects
63+
| { key1: boolean; key2: number } // objects
6464
| { [key: string]: number } // records
65-
| [1, 2] // tuples
65+
| [boolean, number] // tuples
6666
| number[]; // arrays
6767
```
6868

69-
- **Object types** describe objects have a finite number of keys, and each of them contain a value of some specific type.
70-
- **Record types** are like object types, except they describe objects with an unknown number of keys, and every value contained in a record must have the same type. The type `{ [key: string]: number }` tells us that objects of this type contain numbers.
71-
- **Tuple types** describe arrays with a fixed length. They can contain a value of a different type for each index.
72-
- **Array types** describe arrays with an unknown length. Every value contained in an array must have the same type.
69+
- **Object types** describe objects with a finite set of keys, and these keys contain values of potentially different types.
70+
- **Record types** are similar to object types, except they describe objects with an unknown number of keys, and all values contained in a record share the same type. For example all values in an object of type `{ [key: string]: number }` are numbers.
71+
- **Tuple types** describe arrays with a fixed length. They can have a different type for each index.
72+
- **Array types** describe arrays with an unknown length. all values contained in an array type must have the same type.
7373

7474
It makes sense to split those in 2 sub-groups:
7575

7676
- The sub-group of data structures that can contain **several types**: objects and tuples.
7777
- The sub-group of data structures that contain a **single type**: records and arrays.
7878

79-
At the type-level, we will mostly be using Objects and Tuples. They are the type level equivalent of JavaScript's objects and arrays and they will enable to implement some of the mapping and filtering algorithms you are already familiar with.
79+
At the type-level, we will mostly be using objects and tuples. They are the type level equivalent of JavaScript's objects and arrays and they will enable us to implement some of the algorithms you are already familiar with.
8080

81-
Since Records and Array types can only contain a single type inside of them, they aren't very useful in the world of types, so we won't use them very much.
81+
Since records and array types can only contain a single type inside of them, they aren't very useful in type-level programs, so we won't use them very much.
8282

8383
### Union and Intersections are data structures too!
8484

85-
Everything we have seen so far look somewhat similar to the kind of data we have at the value-level, but unions and intersections are different. They are really specific to the type-level, and building a good mental model of how they work is a little more challenging.
85+
Everything we have seen so far looks somewhat similar to the kind of data we have at the value-level, but unions and intersections are different. They are really specific to the type-level, and building a good mental model of how they work is a little more challenging.
8686

8787
Here is what they look like:
8888

@@ -92,9 +92,9 @@ type Intersections = X & Y;
9292
type Unions = X | Y;
9393
```
9494

95-
We often tend to think of `&` and `|` as operators. They definitely look like operators at first sight because we place them in between two other types, but they actually are data structures.
95+
We often tend to think of `&` and `|` as operators. They definitely look like operators at first sight because we place them in between two other types, but they actually are data structures too.
9696

97-
In this course, I'll show you how we can loop through each item inside a union type, how to transform each of them or filter some items to create a new union type from an existing one. This clearly means that `X | Y` doesn't destroy `X` and `Y` to create a new opaque type as an operator would. We will still be able to access `X` and `Y` afterwards and `|` is just a way to add them to some kind of "union" data structure.
97+
In this course, we will see how we can loop through each item inside a union type, how to "map" over a union type to transform each of its items, or how to filter some items out to create a new union type from an existing one. This clearly means that `X | Y` doesn't turn `X` and `Y` into a new opaque type the way an operator would. Since we are still able to access `X` and `Y` afterwards, it looks like `|` is just a way to add them to some kind of "union" data structure.
9898

9999
To get a better grasp at how unions and intersections work, I'll need to take a little detour that is very foundamental to Type-level TypeScript: **all types are Sets**.
100100

0 commit comments

Comments
 (0)