fuzzyworld

tools / commit

adding generics

4a4e9c33a5ecdb67f0e30d98794efc8b096f598d · Pavel Safronov · 2025-08-17 14:30:43 -0700 · parents 3aee11a43130

adding generics
 cheatsheets/apps/index.ts |  7 +++++++
 cheatsheets/typescript.md | 11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/cheatsheets/apps/index.ts b/cheatsheets/apps/index.ts
index 1116078..964966d 100644
--- a/cheatsheets/apps/index.ts
+++ b/cheatsheets/apps/index.ts
@@ -167,3 +167,10 @@ console.log(`26, info:`, info);
 console.log(`27, info.getInfo():`, info.getInfo());
 console.log(`28, info.get size:`, info.size);
 
+interface DataSource<ResponseType> {
+    fetchData(): ResponseType;
+}
+
+interface DataSource2<ResponseType extends { status: number }> {
+    fetchData(): ResponseType;
+}
diff --git a/cheatsheets/typescript.md b/cheatsheets/typescript.md
index 130a98e..3e3b5bb 100644
--- a/cheatsheets/typescript.md
+++ b/cheatsheets/typescript.md
@@ -79,7 +79,6 @@
     map.delete("c"); // removes key "c"
     map.clear(); // removes all entries
     ```
-    - Note: *DO NOT use `Object` as a map key*
   - Set
     ```ts
     const set: Set<number> = new Set([1, 2, 3]);
@@ -149,3 +148,13 @@
         }
     };
     ```
+- generics
+  - example
+    ```ts
+    interface DataSource<ResponseType> {
+        fetchData(): ResponseType;
+    }
+    interface DataSource2<ResponseType extends { status: number }> {
+        fetchData(): ResponseType;
+    }
+    ```