Skip to content

Files

Latest commit

fc74e43 · Jan 20, 2023

History

History
35 lines (23 loc) · 1.76 KB

README.md

File metadata and controls

35 lines (23 loc) · 1.76 KB

Function overload

Author: Thomas Laforge

Information

Angular uses TypeScript, and mastering TypeScript can help you avoid runtime errors by catching them at compile time.

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

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