feat(overload): add readme instruction

This commit is contained in:
thomas
2023-01-20 10:30:37 +01:00
parent fa53d48b09
commit b4b0203ce2
3 changed files with 10 additions and 6 deletions

View File

@@ -4,13 +4,16 @@
### Information ### 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 ### Statement
### Step 1 - Use function overload
- Delete all `throw new Error`
### Step 2
### Constraints:
### Submitting your work ### Submitting your work

View File

@@ -1,5 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { createVehicle } from './teacher.utils'; import { createVehicle } from './vehicle.utils';
@Component({ @Component({
standalone: true, standalone: true,
@@ -8,6 +8,7 @@ import { createVehicle } from './teacher.utils';
}) })
export class AppComponent { export class AppComponent {
car = createVehicle('car', 'diesel'); car = createVehicle('car', 'diesel');
moto = createVehicle('moto', 'diesel');
bus = createVehicle('bus', undefined, 20); bus = createVehicle('bus', undefined, 20);
boat = createVehicle('boat', undefined, 300, true); boat = createVehicle('boat', undefined, 300, true);
bicycle = createVehicle('bicycle'); bicycle = createVehicle('bicycle');