diff --git a/book-content/chapters/05-unions-literals-and-narrowing.md b/book-content/chapters/05-unions-literals-and-narrowing.md index 72faf71..2e529bb 100644 --- a/book-content/chapters/05-unions-literals-and-narrowing.md +++ b/book-content/chapters/05-unions-literals-and-narrowing.md @@ -117,7 +117,7 @@ We could then specify `AlbumFormat` as a union of `DigitalFormat` and `PhysicalF type AlbumFormat = DigitalFormat | PhysicalFormat; ``` -Now, we can use the `DigitalFormat` type for functions that handle digital formats, and the `AnalogFormat` type for functions that handle analog formats. The `AlbumFormat` type can be used for functions that handle all cases. +Now, we can use the `DigitalFormat` type for functions that handle digital formats, and the `PhysicalFormat` type for functions that handle physical formats. The `AlbumFormat` type can be used for functions that handle all cases. This way, we can ensure that each function only handles the cases it's supposed to handle, and TypeScript will throw an error if we try to pass an incorrect format to a function. diff --git a/book-content/chapters/09-typescript-only-features.md b/book-content/chapters/09-typescript-only-features.md index f27f368..a2b59d2 100644 --- a/book-content/chapters/09-typescript-only-features.md +++ b/book-content/chapters/09-typescript-only-features.md @@ -371,18 +371,18 @@ namespace RecordStoreUtils { } ``` -In this example, `AlbumCollection` is the main namespace, with `Sales` as a nested namespace. This structure helps in organizing the code by functionality and makes it clear which part of the application each function pertains to. +In this example, `RecordStoreUtils` is the main namespace, with `Sales` as a nested namespace. This structure helps in organizing the code by functionality and makes it clear which part of the application each function pertains to. -The stuff inside of the `AlbumCollection` can be used as values or types: +The stuff inside of the `RecordStoreUtils` can be used as values or types: ```typescript -const odelay: AlbumCollection.Album.Album = { +const odelay: RecordStoreUtils.Album.Album = { title: "Odelay!", artist: "Beck", year: 1996, }; -AlbumCollection.Sales.recordSale("Odelay!", 1, 10.99); +RecordStoreUtils.Sales.recordSale("Odelay!", 1, 10.99); ``` ### How Namespaces Compile diff --git a/book-content/chapters/14-configuring-typescript.md b/book-content/chapters/14-configuring-typescript.md index 0739f13..a430e2a 100644 --- a/book-content/chapters/14-configuring-typescript.md +++ b/book-content/chapters/14-configuring-typescript.md @@ -17,6 +17,7 @@ To start, here's a recommended base `tsconfig.json` configuration with options a "isolatedModules": true, "strict": true, "noUncheckedIndexedAccess": true + } } ``` diff --git a/book-content/chapters/16-the-utils-folder.md b/book-content/chapters/16-the-utils-folder.md index 3694077..7b2b6a1 100644 --- a/book-content/chapters/16-the-utils-folder.md +++ b/book-content/chapters/16-the-utils-folder.md @@ -496,8 +496,9 @@ function assertIsAlbum(input: unknown): asserts input is Album { "artist" in input && "year" in input ) { - throw new Error("Not an Album!"); + return; } + throw new Error("Not an Album!"); } ``` @@ -522,8 +523,9 @@ function assertIsAlbum(input: unknown): asserts input is Album { "artist" in input && "year" in input ) { - throw new Error("Not an Album!"); + return; } + throw new Error("Not an Album!"); } // ---cut--- function getAlbumTitle(item: unknown) { @@ -548,8 +550,9 @@ For example, if the `assertIsAlbum` function doesn't check for all the required ```typescript function assertIsAlbum(input: unknown): asserts input is Album { if (typeof input === "object") { - throw new Error("Not an Album!"); + return; } + throw new Error("Not an Album!"); } let item = null;