DEV Community

Discussion on: Code Smell 87 - Inconsistent Parameters Sorting

Collapse
 
jamesrweb profile image
James Robb

Usually for cases like this I would create a factory to avoid the ambiguity, something like:

type Vaccine = "pfizer" | "moderna"
type Patient = {
    name: string;
}
type PatientWithCoronaVaccineDetails = Patient & {
    vaccine: Vaccine;
    doses: number;
}

function vaccineFactoryForPatient(patient: PatientWithCoronaVaccineDetails) {
  // ...

  return {
    giveFirstDoseOfVaccine() {
        // ...
    },
    giveSecondDoseOfVaccine() {
        // ...
    }
  }
}
}
Enter fullscreen mode Exit fullscreen mode

This way we can avoid this category of issues in the first place.