diff --git a/book-content/chapters/04-essential-types-and-annotations.md b/book-content/chapters/04-essential-types-and-annotations.md index f677303..e3e2acf 100644 --- a/book-content/chapters/04-essential-types-and-annotations.md +++ b/book-content/chapters/04-essential-types-and-annotations.md @@ -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 = { diff --git a/book-content/chapters/07-mutability.md b/book-content/chapters/07-mutability.md index 2f6f5d1..3c5afb9 100644 --- a/book-content/chapters/07-mutability.md +++ b/book-content/chapters/07-mutability.md @@ -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. diff --git a/book-content/chapters/10-deriving-types.md b/book-content/chapters/10-deriving-types.md index 3bac800..925c279 100644 --- a/book-content/chapters/10-deriving-types.md +++ b/book-content/chapters/10-deriving-types.md @@ -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: @@ -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 = { diff --git a/book-content/chapters/11-annotations-and-assertions.md b/book-content/chapters/11-annotations-and-assertions.md index 13283a5..03d9861 100644 --- a/book-content/chapters/11-annotations-and-assertions.md +++ b/book-content/chapters/11-annotations-and-assertions.md @@ -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. @@ -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. diff --git a/book-content/chapters/12-the-weird-parts.md b/book-content/chapters/12-the-weird-parts.md index 79364d9..0c980f7 100644 --- a/book-content/chapters/12-the-weird-parts.md +++ b/book-content/chapters/12-the-weird-parts.md @@ -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 diff --git a/book-content/chapters/13-modules-scripts-declaration-files.md b/book-content/chapters/13-modules-scripts-declaration-files.md index 2c951ee..ad9ee12 100644 --- a/book-content/chapters/13-modules-scripts-declaration-files.md +++ b/book-content/chapters/13-modules-scripts-declaration-files.md @@ -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); ``` @@ -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: diff --git a/book-content/chapters/14-configuring-typescript.md b/book-content/chapters/14-configuring-typescript.md index c79f612..0739f13 100644 --- a/book-content/chapters/14-configuring-typescript.md +++ b/book-content/chapters/14-configuring-typescript.md @@ -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 diff --git a/book-content/chapters/15-designing-your-types.md b/book-content/chapters/15-designing-your-types.md index 39193e7..4de2015 100644 --- a/book-content/chapters/15-designing-your-types.md +++ b/book-content/chapters/15-designing-your-types.md @@ -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 = @@ -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: diff --git a/book-content/chapters/16-the-utils-folder.md b/book-content/chapters/16-the-utils-folder.md index fdc2e0d..3694077 100644 --- a/book-content/chapters/16-the-utils-folder.md +++ b/book-content/chapters/16-the-utils-folder.md @@ -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`. 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`. This will require you to combine generic types and functions to ensure that the tests pass successfully. @@ -1197,7 +1197,7 @@ const objMap = createStringMap(); const objMap: Map; ``` -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