From e675ddd6734e8b6fef52e27bc3d7ffafeeb451d1 Mon Sep 17 00:00:00 2001 From: Fiodar Savutsin Date: Wed, 31 Jul 2024 01:47:11 +0300 Subject: [PATCH 1/2] fix: fix examples in Assertion functions --- book-content/chapters/16-the-utils-folder.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/book-content/chapters/16-the-utils-folder.md b/book-content/chapters/16-the-utils-folder.md index 3694077..908ec97 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,11 +550,12 @@ 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; +let item: unknown = null; assertIsAlbum(item); From 58771fe94dc69235f4d1b3f0e1f18e59c24e5411 Mon Sep 17 00:00:00 2001 From: Fiodar Savutsin Date: Wed, 31 Jul 2024 01:54:19 +0300 Subject: [PATCH 2/2] fix: fix link to exercise 4 --- book-content/chapters/16-the-utils-folder.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book-content/chapters/16-the-utils-folder.md b/book-content/chapters/16-the-utils-folder.md index 908ec97..d4bb8b6 100644 --- a/book-content/chapters/16-the-utils-folder.md +++ b/book-content/chapters/16-the-utils-folder.md @@ -880,7 +880,7 @@ it("Should accept a custom error", () => { Your task is to update the `addCodeToError` type signature to enforce the required constraints so that `TError` is required to have a `message` property and can optionally have a `code` property. - + ### Exercise 5: Combining Generic Types and Functions