Пропустить до содержимого
angular challenges logo Angular Challenges

🟠 Function Overload

Испытание #15

Это содержимое пока не доступно на вашем языке.

Создано 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

Контрибьюторы

Спасибо всем контрибьюторам которые помогли сделать эту документацию лучше!

  • tomalaforge
  • LMFinney