Files
angular-challenges/apps/overload

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

  1. Fork the project
  2. clone it
  3. npm install
  4. npx nx serve overload
  5. ...work on it
  6. Commit your work
  7. Submit a PR with a title beginning with Answer:15 that I will review and other dev can review.

overload

You can ask any question on twitter