How does one do proper type validation in TypeScript? I currently have this but having to constantly cast is quite annoying.
const toNewEntry = (obj: unknown): EntryWithoutId => {
const isObject = (v: unknown) => v && typeof v === "object"
const isEntry = (v: object) => "description" in v && "date" in v && "specialist" in v && "type" in v
const isHospitalEntry = (v: EntryWithoutId): boolean => v.type === "Hospital" &&
"discharge" in v &&
"date" in v.discharge &&
"criteria" in v.discharge
const isHealthCheckEntry = (v: EntryWithoutId): boolean => v.type === "HealthCheck" &&
"healthCheckrating" in v
const isOccupationalHealthcareEntry = (v: EntryWithoutId): boolean => v.type === "OccupationalHealthcare" &&
"emloyerName" in v
...