I currently have the following interface:
export interface Vehicle {
id: number;
type: 'car' | 'airplane';
jet_engines?: number;
wheels?: number;
}
But I also don't want cars to accept the jet_engines property, and airplanes shouldn't have the wheels property.
I want to use it like this:
const func = (vehicle: Vehicle) => {
if (vehicle.type === 'airplane') {
// TS should know here that `jet_engines` exists in `vehicle`.
}
}
I want to avoid using like this:
const func = (vehicle: Car | Airplane) => {
Is this possible? Is this possible while keeping Vehicle an interface (not changing it to a type)?
typevorVehicle?