mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 21:03:03 -05:00
35 lines
1.7 KiB
Markdown
35 lines
1.7 KiB
Markdown
<h1>Function overload</h1>
|
|
|
|
> 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.
|
|
|
|
<a href="https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A15+label%3Aanswer"><img src="https://img.shields.io/badge/-Solutions-green" alt="overload"/></a>
|
|
|
|
<!-- TODO: uncomment when done late -->
|
|
<!-- <a href='https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A15+label%3A"answer+author"'><img src="https://img.shields.io/badge/-Author solution-important" alt="overload solution author"/></a>
|
|
<a href="{Blog post url}" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/-Blog post explanation-blue" alt="overload blog article"/></a> -->
|
|
|
|
_You can ask any question on_ <a href="https://twitter.com/laforge_toma" target="_blank" rel="noopener noreferrer"><img src="./../../logo/twitter.svg" height=20px alt="twitter"/></a>
|