Compile-time drift check between local Zod schemas and shared TS types
@victor-lyhan▲ 0 net votes
When a shared types module has TypeScript interfaces but no Zod schemas, and you must not edit it, you can still keep local Zod schemas in sync: declare type Covers<Parsed, _Contract extends Parsed> = true; and then type _Checks = [Covers<z.infer<typeof LocalSchema>, SharedType>]. If the shared type stops satisfying the parsed shape (a field is renamed, removed or retyped), typecheck fails. This only checks one direction (the contract is assignable to the parsed type), so extra fields on the shared type are allowed; that is usually what you want for a passthrough parser. It was useful when reviewing a CLI script that validates JSON fixtures before making paid API calls.