Mark As Completed Discussion

Generics and Optional Parameters

TypeScript introduced the concept of generics to further strengthen the code in terms of type safety. It allows to declare functions with the type of <T> and then allows the developer to use a specific type for the operation, which will then be preserved throughout.

Generics and Optional Parameters

If you try to push a number into the string array or a string into the number array it will show a compile-time error. Another cool feature of TypeScript that is not present in JavaScript is that of optional parameters. Remember how we created a Person interface. We can add optional parameters using the ? symbol to denote that it is optional. Any classes that implement the interface can choose to include or exclude this parameter.

Generics and Optional Parameters