Skip to content

Commit

Permalink
Merge pull request #40 from gdarchen/fix/typos
Browse files Browse the repository at this point in the history
fix(typos): fix some typos found in the book content
  • Loading branch information
mattpocock committed Jul 25, 2024
2 parents f3120fb + 9f55f6c commit f0726bf
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ type ShoppingCart = {

There are a few different ways to express an array of objects.

One approach would be to to create a new `Ingredient` type that we can use to represent the objects in the array:
One approach would be to create a new `Ingredient` type that we can use to represent the objects in the array:

```ts twoslash
type Ingredient = {
Expand Down
2 changes: 1 addition & 1 deletion book-content/chapters/07-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,6 @@ const buttonsToChange: (
)[];
```
But again, this is still typed strongly enough to to satisfy `modifyButtons`.
But again, this is still typed strongly enough to satisfy `modifyButtons`.
When using `as const` like this acts like a hint to TypeScript that it should infer a literal type where it wouldn't otherwise. This can be occasionally useful for when you want to allow mutation, but still want to infer a literal type.
4 changes: 2 additions & 2 deletions book-content/chapters/10-deriving-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Use the `typeof` keyword whenever you need to extract types based on runtime val

### You Can't Create Runtime Types from Values

We've seen that `typeof` can create types from runtime values, but it's important to note that there is no way to to create a value from a type.
We've seen that `typeof` can create types from runtime values, but it's important to note that there is no way to create a value from a type.

In other words, there is no `valueof` operator:

Expand Down Expand Up @@ -559,7 +559,7 @@ Your task is to update the `Environment` type so that it is derived from the `co

### Exercise 3: Accessing Specific Values

Here were have an `programModeEnumMap` object that keeps different groupings in sync. There is also a `ProgramModeMap` type that uses `typeof` to represent the entire enum mapping:
Here we have an `programModeEnumMap` object that keeps different groupings in sync. There is also a `ProgramModeMap` type that uses `typeof` to represent the entire enum mapping:

```typescript
export const programModeEnumMap = {
Expand Down
4 changes: 2 additions & 2 deletions book-content/chapters/11-annotations-and-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ This allows us to specify that the values we pass to our configuration object mu

Let's work through the solutions for `satisfies`, `as`, and variable annotations.

#### When to Use `satifies`
#### When to Use `satisfies`

For the first scenario that uses a `Record`, the `satisfies` keyword won't work because we can't add dynamic members to an empty object.

Expand Down Expand Up @@ -1193,4 +1193,4 @@ const routes = {

Now our tests pass expected.

This setup of combining `as const` and `satisfies` is ideal when you need a particular shape for a configuration object and want while enforcing immutability.
This setup of combining `as const` and `satisfies` is ideal when you need a particular shape for a configuration object while enforcing immutability.
2 changes: 1 addition & 1 deletion book-content/chapters/12-the-weird-parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ playSong(Song);

In this case, TypeScript shows an error when we try to pass the `Song` class itself to the `playSong` function. This is because `Song` is a class, and not an instance of the class.

So, classes exists in both the type and value worlds, and represents an instance of the class when used as a type.
So, classes exist in both the type and value worlds, and represent an instance of the class when used as a type.

### Enums

Expand Down
6 changes: 3 additions & 3 deletions book-content/chapters/13-modules-scripts-declaration-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ declare module "duration-utils" {

We use `export` to define what is being exported from the module.

Like before, we are not including any implementation code in the `.d.ts` file– it's just the types that are being declared.
Like before, we are not including any implementation code in the `.d.ts` file – it's just the types that are being declared.

Once the `duration-utils.d.ts` file is created, the module can be imported and used as usual:

```typescript
import { formatDuration, parseTrackData } from "music-utils";
import { formatDuration, parseTrackData } from "duration-utils";

const formattedTime = formatDuration(309);
```
Expand Down Expand Up @@ -468,7 +468,7 @@ const numbers = [1, 2, 3];
numbers.map((n) => n * 2);
```

Let's step back for a minute. How does TypeScript know that `.map` exists on an array? How does it know that `.map` exists, but `.transform` doesn't? Where is this defined
Let's step back for a minute. How does TypeScript know that `.map` exists on an array? How does it know that `.map` exists, but `.transform` doesn't? Where is this defined?

As it turns out, TypeScript ships with a bunch of declaration files that describe the JavaScript environment. We can do a 'go to definition' on `.map` to see where that is:

Expand Down
2 changes: 1 addition & 1 deletion book-content/chapters/14-configuring-typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ The common settings can be moved to `tsconfig.base.json`:
}
```

Then, the `client/tsconfig.json` would extend the base configuration wit the `extends` option that points to the `tsconfig.base.json` file:
Then, the `client/tsconfig.json` would extend the base configuration with the `extends` option that points to the `tsconfig.base.json` file:

```tsx
// client/tsconfig.json
Expand Down
4 changes: 2 additions & 2 deletions book-content/chapters/15-designing-your-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ TypeScript shows an error that tells us that `ResourceStatus` requires two type

In some cases, you may want to provide default types for generic type parameters. Like with functions, you can use the `=` to assign a default value.

By setting `TMetadata`'s default value to an empty, we can essentially make `TMetadata` optional:
By setting `TMetadata`'s default value to an empty object, we can essentially make `TMetadata` optional:

```tsx
type ResourceStatus<TContent, TMetadata = {}> =
Expand Down Expand Up @@ -549,7 +549,7 @@ Conditional types turn TypeScript's type system into a full programming language

## Mapped Types

Mapped types in TypeScript allow you to create a new object type based on an existing type by iterating over its keys and values. This can be let you be extremely expressive when creating new object types.
Mapped types in TypeScript allow you to create a new object type based on an existing type by iterating over its keys and values. This can let you be extremely expressive when creating new object types.

Consider this `Album` interface:

Expand Down
4 changes: 2 additions & 2 deletions book-content/chapters/16-the-utils-folder.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ it("should return the result if the function succeeds", async () => {
});
```

Your task is to update `safeFunction` to have a generic type parameter, and update `PromiseFunc` to not return `Promise<Any>`. This will require you to combine generic types and functions to ensure that the tests pass successfully.
Your task is to update `safeFunction` to have a generic type parameter, and update `PromiseFunc` to not return `Promise<any>`. This will require you to combine generic types and functions to ensure that the tests pass successfully.

<Exercise title="Exercise 5: Combining Generic Types and Functions" filePath="/src/085-the-utils-folder/219-combining-generic-types-with-generic-functions.problem.ts"></Exercise>

Expand Down Expand Up @@ -1197,7 +1197,7 @@ const objMap = createStringMap();
const objMap: Map<string, unknown>;
```

Through these steps, we've successfully transformed `createStringMap` from a regular function into a generic function capable of receiving type arguments .
Through these steps, we've successfully transformed `createStringMap` from a regular function into a generic function capable of receiving type arguments.

### Solution 2: Default Type Arguments

Expand Down

0 comments on commit f0726bf

Please sign in to comment.