function validateCar(car: ICar) {
...
}
This function serves as a gatekeeper, stipulating that only objects conforming to the ICar
interface can be assigned to the local variable car
.
No actual interface is physically handed over in this process.
Picture it like a vigilant doorman, selectively permitting certain inputs.
this.validateCar({make: "Toyota", model: "Camry"});
This represents an invocation of the validateCar function using an object that may or may not meet the requirements of the ICar
interface.
In typescript, type checking occurs at compile time, meaning any errors will show up when running the compiler with tsc
.
Remember, if you pass a different data type during runtime, there won't be validation checks, potentially leading to faulty code execution.