I have two arrays of objects in my code, one is holding form data, the other is holding additional info used to spruce up the form. While looping over my form data, I get the relevant object like this:
type fields = {car_id: number; // ...}[];
type cars = {car_id: number; //... }[];
fields.map((field) => {
const car = cars.find((car) => car.car_id === field.car_id); // car might be undefined while in reality it never is
// do something with car
});
Is there a way to handle this in typescript so it knows a car will always be found?