From fc74e43ddb11d7115b5b14ac0b2091dec1537398 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 20 Jan 2023 11:11:35 +0100 Subject: [PATCH] feat(overload): add challenge 15 --- README.md | 9 +++++++-- apps/overload/README.md | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 376172a..5714f4b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

-

Collection of Angular challenges

+

Collection of Angular challenges


@@ -34,6 +34,11 @@ This goal of this project is to help you get better at Angular and NgRx by resol change detection with scroll event styling +
+Typescript + +Overload function +
RxJs @@ -56,7 +61,7 @@ This goal of this project is to help you get better at Angular and NgRx by resol - +
Thomas Laforge
Thomas Laforge

13 🧩
Thomas Laforge
Thomas Laforge

15 🧩
diff --git a/apps/overload/README.md b/apps/overload/README.md index cf38567..21027e7 100644 --- a/apps/overload/README.md +++ b/apps/overload/README.md @@ -4,16 +4,17 @@ ### Information -Angular is using Typescript and mastering Typescript can help you avoid runtime errors at compile time. In this challenge, we have a function to create a vehicle. -But each vehicle type needs different type of property. Right now we are throwing an error at runtime which is less than ideal since we can catch this error at compile time. +Angular uses TypeScript, and mastering TypeScript can help you avoid runtime errors by catching them at compile time. -One easy way would be to create a function per vehicle type but for this challenge I want to use the same fonction and depending on the type passed as first parameter , Typescript should autocomplete for you. -To archieve this, we will use function overload. +In this challenge, we have a function to create a vehicle. However, each vehicle type requires different mandatory properties. +Currently, we are getting an error at runtime if one property is missing and we don't get the return Type, which is not ideal. +One solution would be to create a separate function for each vehicle type, but for this challenge, I want to use the same function and have TypeScript automatically complete the properties depending on the type passed as the first parameter. + +To achieve this, we will use overload functions. ### Statement - Use function overload -- Delete all `throw new Error` ### Submitting your work