From ac9d55e4831c00b4729aee3876d49ec244c33098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samet=20=C3=87EL=C4=B0KBI=C3=87AK?= Date: Wed, 4 Sep 2024 16:46:12 +0300 Subject: [PATCH 1/3] Rename ALBUM_API to MUSIC_API --- .../chapters/13-modules-scripts-declaration-files.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/book-content/chapters/13-modules-scripts-declaration-files.md b/book-content/chapters/13-modules-scripts-declaration-files.md index ad9ee12..b9f5090 100644 --- a/book-content/chapters/13-modules-scripts-declaration-files.md +++ b/book-content/chapters/13-modules-scripts-declaration-files.md @@ -280,13 +280,13 @@ type Album = { releaseDate: string; }; -declare const ALBUM_API: { +declare const MUSIC_API: { getAlbumInfo(upc: string): Promise; searchAlbums(query: string): Promise; }; ``` -Because we haven't included any imports or exports, this file is treated as a script. This means that the `ALBUM_API` variable is now available globally in our project. +Because we haven't included any imports or exports, this file is treated as a script. This means that the `MUSIC_API` variable is now available globally in our project. #### Scoping Global Variables To One File @@ -301,17 +301,17 @@ type Album = { releaseDate: string; }; -declare const ALBUM_API: { +declare const MUSIC_API: { getAlbumInfo(upc: string): Promise; searchAlbums(query: string): Promise; }; export function getAlbumTitle(upc: string) { - return ALBUM_API.getAlbumInfo(upc).then((album) => album.title); + return MUSIC_API.getAlbumInfo(upc).then((album) => album.title); } ``` -Now, `ALBUM_API` is only available in the `musicUtils.ts` file. `declare` defines the value within the scope it's currently in. So, because we're now inside a module (due to the `export` statement), `ALBUM_API` is scoped to this module. +Now, `MUSIC_API` is only available in the `musicUtils.ts` file. `declare` defines the value within the scope it's currently in. So, because we're now inside a module (due to the `export` statement), `MUSIC_API` is scoped to this module. #### `declare const`, `declare var`, `declare let`, `declare function` From 4614d216951abfaa96507b694739944dd5b19067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samet=20=C3=87EL=C4=B0KBI=C3=87AK?= Date: Wed, 4 Sep 2024 16:52:00 +0300 Subject: [PATCH 2/3] Rename missing parts --- .../chapters/13-modules-scripts-declaration-files.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book-content/chapters/13-modules-scripts-declaration-files.md b/book-content/chapters/13-modules-scripts-declaration-files.md index b9f5090..38a51ea 100644 --- a/book-content/chapters/13-modules-scripts-declaration-files.md +++ b/book-content/chapters/13-modules-scripts-declaration-files.md @@ -343,7 +343,7 @@ type Album = { // ---cut--- // inside musicUtils.ts declare global { - declare const ALBUM_API: { + declare const MUSIC_API: { getAlbumInfo(upc: string): Promise; searchAlbums(query: string): Promise; }; @@ -356,14 +356,14 @@ This almost works, except for the error. We can't use `declare` inside an ambien // inside musicUtils.ts declare global { - const ALBUM_API: { + const MUSIC_API: { getAlbumInfo(upc: string): Promise; searchAlbums(query: string): Promise; }; } ``` -Now the `ALBUM_API` variable has been put into the global scope. +Now the `MUSIC_API` variable has been put into the global scope. ### `declare module` From f4b8e8b58f0d29e7710742e5fe68adf4d8de38ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samet=20=C3=87EL=C4=B0KBI=C3=87AK?= Date: Fri, 6 Sep 2024 18:02:32 +0300 Subject: [PATCH 3/3] Add missing info --- 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 3694077..8149e50 100644 --- a/book-content/chapters/16-the-utils-folder.md +++ b/book-content/chapters/16-the-utils-folder.md @@ -216,7 +216,7 @@ const getFirstElement = (arr: TMember[]) => { Just like generic functions, it's common to prefix your type parameters with `T` to differentiate them from normal types. -Now when we call `getFirstElement`, TypeScript will infer the type of `` based on the argument we pass in: +Now when we call `getFirstElement`, TypeScript will infer the type of `TMember` based on the argument we pass in: ```ts twoslash const getFirstElement = (arr: TMember[]) => {