mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(overload): add readme instruction
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|||||||
Reference in New Issue
Block a user