File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -78,18 +78,21 @@ Generics offer a way to create reusable components. Generics provide a way to ma
7878** Example:**
7979
8080``` ts
81+ /**
82+ * Generics
83+ */
8184function getArray<T >(items : T [] ) : T [] {
8285 return new Array <T >().concat (items );
8386}
8487
85- let myNumArr = getArray <number >([100 , 200 , 300 ]);
86- let myStrArr = getArray <string >([" Hello" , " World" ]);
88+ let numArr = getArray <number >([10 , 20 , 30 ]);
89+ let strArr = getArray <string >([" Hello" , " World" ]);
8790
88- myNumArr .push (400 ); // OK
89- myStrArr .push (" Hello TypeScript" ); // OK
91+ numArr .push (40 ); // OK
92+ strArr .push (" Hello TypeScript" ); // OK
9093
91- myNumArr .push (" Hi" ); // Compiler Error
92- myStrArr .push (500 ); // Compiler Error
94+ numArr .push (" Hi" ); // Compiler Error
95+ strArr .push (50 ); // Compiler Error
9396```
9497
9598<div align =" right " >
You can’t perform that action at this time.
0 commit comments