Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict typing, type errors, `infer`, `extends`, conditional types, mapped types, template literal types, branded/opaque types, or utility types like `Partial`, `Record`, `ReturnType`, and `Awaited`.
87
95%
Does it follow best practices?
Impact
76%
1.16xAverage score across 5 eval scenarios
Passed
No known issues
A healthcare data platform stores and processes sensitive records including patient IDs, provider IDs, appointment IDs, validated email addresses, and license numbers. The current TypeScript codebase uses plain string for all of these, which has led to a production incident: a developer accidentally passed a providerId where a patientId was expected, and the resulting data corruption wasn't caught until end-to-end tests ran hours later.
The engineering team wants to harden this module so that TypeScript itself prevents mixing of these semantically distinct identifiers at compile time — without changing the runtime representation. They also want a principled way to validate raw strings (from API inputs) into these stronger types, covering two patterns: one where invalid input should throw immediately, and one where the caller decides how to handle the failure.
Produce a TypeScript file healthcare-types.ts that:
PatientId, ProviderId, AppointmentId, ValidatedEmailstring inputs into these typesAlso produce a README.md that explains the type-theoretic reason this approach works, including a before/after code comparison showing how the old plain-string approach allowed bugs.
If you use utility types to extract return types from any async functions in the module, document how you apply them correctly.
Include a type-tests.ts file with compile-time assertions verifying the type constraints hold.