mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
Function overload
Author: Thomas Laforge
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.
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.
Statement
- Use function overload
- Delete all
throw new Error
Submitting your work
- Fork the project
- clone it
- npm install
npx nx serve overload- ...work on it
- Commit your work
- Submit a PR with a title beginning with Answer:15 that I will review and other dev can review.