Typescript – Activating a class method in a separate class

  Kiến thức lập trình

I am working on a school assignment where I have to modify a vehicle selection interface to include a truck that can tow other vehicles. Vehicles that are not trucks cannot tow other vehicles. I created the Truck class in Truck.ts and created a method called tow.

In the Cli (I did not chose the names for these files and notified the admin about the inappropriate file name pun) there is a method called findVehicleToTow where the tow method is called when the vehicle of type Truck towing any vehicle besides itself.

I tried several methods to call tow, but I frequently get “property tow does not exist on type of Truck.

My teacher said to pass an array through the vehicles array and find the truck class. I can do that with a for and if, but I do not know what to do within the if statement to declare the class as a variable or string so I can call the tow method.

let towTruck = this.vehicles.filter((Truck) => {
          if (towTruck === Truck) {
            return true;
          }
        }
      )
towTruck.tow(answers.vehicleToTow.vin);

I am super new to this and need the most basic explanation.

https://github.com/sketchyTK/Module-8-Challenge-Vehicle-Builder/blob/main/src/classes/Cli.ts

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT