After creating a class and instantiating an object from it through the constructor, I expected to receive an error message indicating missing properties. However, despite the fact that the class description specified required fields, I was able to create an object without including them explicitly, and no errors were thrown. Strangely, when attempting to create an object using "const toyota: Vehicle = {}", an error did occur. Why is this discrepancy happening?
class Vehicle {
isSpecial: boolean;
wheels: number;
brand: string;
model: string;
mileage: number;
isUsed: boolean;
constructor (wheels: number, mileage: number) {
this.wheels = wheels;
this.mileage = mileage;
}
drive(): void {
this.mileage += 100;
};
}
const toyota: Vehicle = new Vehicle(4, 200);
console.log(toyota);
Expected: error "Type '{}' is missing the following properties from type 'Vehicle': isSpecial, brand, model, and 2 more." Actual: no errors, object created