import type { IsNever, Simplify } from "type-fest"; import { JustOneOf, StringKeys, ValueOf } from "./utils"; export type TypeMismatchError = { error: TError["error"]; actual: Simplify; expected: Simplify; }; /** * Extracts all TypeMismatchError's from the projection result, * making it easy to report these errors. * Returns a string of error messages, * or `never` if there are no errors. */ export type ExtractTypeMismatchErrors = ValueOf<{ [TKey in StringKeys]: TypeMismatchError extends TProjectionResult[TKey] ? Extract["error"] : never; }>; /** * When we map projection results, we return TypeMismatchError's * for any fields that have an invalid mapping configuration. * However, this does not cause TypeScript to throw any errors. * * In order to get TypeScript to complain about these invalid mappings, * we will "require" an extra parameter, which will reveal the error messages. */ export type RequireAFakeParameterIfThereAreTypeMismatchErrors> = IsNever<_Errors> extends true ? [] : ["⛔️ Error: this projection has an invalid property ⛔️"] | [JustOneOf<_Errors>];